0

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

johannes
  • 7,262
  • 5
  • 38
  • 57
Thaier Alkhateeb
  • 585
  • 5
  • 8
  • 18
  • 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-websites – MedicineMan May 05 '09 at 17:36

3 Answers3

5

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.

Community
  • 1
  • 1
Jhonny D. Cano -Leftware-
  • 17,663
  • 14
  • 81
  • 103
  • "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
2

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.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
1

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

Mark S. Rasmussen
  • 34,696
  • 4
  • 39
  • 58