views:

151

answers:

4

Can someone explain the concept of sessions in ASP.NET? How do I use them, and how do cookies fit in?

+1  A: 

Session is a per-user object for persisting state between HTTP requests. It is good for storing information that you will need on the server to properly serve requests back to the user (e.g. user name, email, etc.).

ASP.NET places a cookie on the client's machine that contains a GUID (in the case of cookieless sessions, this GUID is placed on the URL). This GUID is the user's session ID. This identifier is retrieved on each HTTP request from the client by the ASP.NET runtime. Subsequently this identifier is used to rehydrate the user's session data from the session's data-store (either in memory or in the database).

Andrew Hare
Or, in the case of cookieless sessions, it's passed in the URL.
GalacticCowboy
@GalacticCowboy: Yes, good correction!
Andrew Hare
A: 
Jonathan Sampson
A: 

Sounds like you're pretty new to ASP.NET. Rather than posting vague questions here, I would suggest you head over to http://www.ASP.net and check out their tutorials. They've got a lot of walkthroughs and articles that will give you a good overview of how ASP.NET state works.

JonnyD
A: 

A question like this makes me want to point you over to a post I did a while back (http://stackoverflow.com/questions/1052080/should-i-use-a-framework-while-learning-web-development/1052127#1052127) which will give you a heads up to other areas you might want to study up on. The topic of sessions is one of those bullet points.

I think that the idea of a session is well covered in the above posts so I won't further detail that!

Andrew Siemer