views:

175

answers:

3

Please I need a clear example about session in asp.net using c# for example(using session in log in operation) and thank you very much......

+1  A: 

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

Mark S. Rasmussen
+5  A: 

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.

Jhonny D. Cano -Leftware-
it's as simple as that :)
The real napster
"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
+2  A: 

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