Take the 2-minute tour ×

I need a detailed example about session in asp.net using c# For example(using session in log in operation

share|improve this question
Please edit your question to include details. Do you want to see how login works? Or do you want to know how long a session lasts? How to store and retrieve data from a session? –  Andrew Arnott Apr 25 '09 at 14:45
I think we should not vote to close until this new member has a chance to provide some detail. If no detail is forthcoming, then it should be closed. –  John Saunders Apr 25 '09 at 14:59
you might be interested in this posting as wellhttp://stackoverflow.com/questions/769338/use-of-session-in-high-traffic-web‌​sites –  MedicineMan May 5 '09 at 17:36
add comment

3 Answers

up vote 1 down vote accepted

You might consider using Forms Authentication: http://msdn.microsoft.com/en-us/library/aa480476.aspx

share|improve this answer
add comment

The Session is the system in ASP.Net where you can save objects and variables User-based, so these items can be available across postbacks.

Adding a variable to the Session:

Session["key"] = myVar;

Retrieving a variable

myVar = Session["key"];
myVar = (MyType) Session["key"];

In the Session, you can save any .NET Framework type, But you should be very aware of the impact this design can weigh in your application, as this imposes scalability issues.

In the answer to this question there is an excellent utility class that can help you to abstract the session object, also take a look at it.

share|improve this answer
it's as simple as that :) –  The real napster Apr 25 '09 at 14:49
"But you should be very aware of the impact this design can weigh in your application" - agreed - for example, storing a 1MB dataset can result in 20MB of server storage to pack and un-pack it, and this will happen on every page request. –  Zhaph - Ben Duguid Apr 25 '09 at 15:03
add comment

Sorry, not entirely sure what you're after with the login stuff, but using session is fairly trivial, the following two pages from MSDN should get you started:

If you've got the standard login controls on a page you can handle the LoggedIn Event to store additional details in the users Session State.

share|improve this answer
add comment

Your Answer


