ASP.NET Session State

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • Session["Session_Key"] = Obj_Value;

Remarks

HTTP is stateless. ASP.NET session state is a framework that facilitates maintaining state between HTTP page requests.

Session differs from the class level variables in its ability to remain available across post-backs and different pages. For instance, a session variable created in Page1.aspx will be available if the user is redirected to Page2.aspx afterwards, within the same application.

Also, in contrast to static variables declared at the page level, the session variables are independent for different users. Meaning, changing the value of one user's session variable will not affect the value of the same variable for other users.

While ViewState can be used to store user's data temporarily, it doesn't allow saving data across multiple pages. In addition, the viewstate is part of the page and is sent to the client. As a result, any critical information related to the user cannot be saved in the ViewState, and that's where Session variables become useful.



Got any ASP.NET Question?