views:

124

answers:

5

What are three ways in which web applications can provide a stateful experience for the user?(using http) I know Sessions and Cookies are two of them, but don't know a third (database??)

Yes a question from a lecture.

A: 

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.

lomaxx
these also come into play:* Control State (akin to ViewState)* Hidden Fields* Profile Properties* Application State
John K
+6  A: 

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.

mjv
I can't upvote this answer enough
Craig Walker
ViewState is a special case of 100% of the context passed back by the client (unless you change the default behaviour).
erikkallen
@erikkallen Thanks for pointing that out; I edited accordingly.
mjv
A: 

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

Rafe Lavelle
Your sample querystring does not represent statefulness.
Justice
I thought they did. "...query string is another ASP.NET client side state management technique." from ASP.NET - Query Strings - Client Side State Management - http://dotnet.dzone.com/news/aspnet-query-strings-client-si
Rafe Lavelle
I think I know whet you mean. I might have been careless - edited post
Rafe Lavelle
A: 

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.

David Thibault
A: 

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.

OMG Ponies