What is Session in ASP.NET?

Sessions are basically server variables that are used to store information on Server.

Session in ASP.NET enables you to store information on server & access that stored information on your sub-sequent web-requests.

HTTP is a stateless protocol, it means every web-request is a new web-request in itself. It does not hold or preserve previous request data. So, Sessions provides us a way to identify the user from on the subsequent web requests.

How to set a value in session in C#:

 Session["Email"] = "ankushjain358@gmail.com";

How to retrieve the stored value from the session:

 string email = Convert.ToString(Session["Email"])

I have covered only basics. You should also study below advanced topics related to Session:

  • Session Identifier
  • Session State Modes