Stateful experience
What are three ways in which web applications can provide a stateful experience for the user?(using开发者_Python百科 http) I know Sessions and Cookies are two of them, but don't know a third (database??)
Yes a question from a lecture.
There are effectively only two approaches:
- Identify the user behind each request and associate this identify with a session context (stored in memory, in database, where-ever) That's where session IDs or cookies (for ID purposes) come in.
- Manage that 100% of the context be passed back by the client (embedding the context in the urls or forms which will be used by the client; ViewState works in this fashion (*). Also, Cookies can be used as well to store such context.
The way the context data is persisted between requests and, for the systems that are based upon identifying the user, the way the identity is supplied, provide many variations upon the two approaches listed above. For example:
- context in database,
- context in memory
- context in a file
- context passed in ViewState (*)
- context ...,
- context stored in a cookie
- ID from SessionID passed on URL/Form
- ID from Cookie
(*) edit: I had originally ViewState marked as a session ID passing device, but as pointed by erikkallen, the default use of ViewState is with passing the context info, not the ID.
In the end, however, it all hinges on whether the context is stored server side or shuttled to/from the client with each request.
There's more than three.
- Session State
- View State
- Cookies
- Database
- Cache
- Writing data to files
Basically anything that can be used persist data across a web request can be used to store state.
Looks like a homework question. Anyway, it's vague.. Ways to track a user? Ways to store a user's data?
Tracking can be done with cookies, url token or a hidden field (in case of forms).
Storing data can be done a lot of different ways.
The most common scenario is storing a session id in a cookie, and using that id to retrieve the user's session.
AJAX is the 3rd piece to making the stateless web application appear as stateful.
It's still submitting requests behind the scenes, but to the user - the screen doesn't refresh or look like a website.
You can have a database driven website, but it won't be stateful.
Querystrings are one of the most common ways of doing this. E.g.
http://www.site.com/products/index.aspx?productId=3&page=2&showInactive=n
精彩评论