Tuesday, 18 November 2014

What is Session State In Asp.Net

  1. ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request.Session is defined as the period of time that a unique user interacts with a Web application. When a new user begins to interact with the application, a new session ID is generated and associated with all subsequent requests from that same client and stored in a cookie on the client machine.
  2. Session state is maintained in an instance of the HttpSessionState class and is accessible through the Session property of both the Page and HttpContext classes. It is not necessary for you to instantiate the Session Object. An instance is automatically provided for you. The Session object allows you to maintain a list of name/value pairs that can be accessed by any Web page in your application.
C#
  string Username;
  if (Session["Username"] != null)
  {
 Username = (String)Session["Username"];
  }
  else
  {
 Session["Usernames"] = "Ashok";
}



For every client Session data store separately, means session data is stored as per client basis. Along with advantages, some times session can causes performance issue for heavy traffic sites because its stored on server memory and clients read data from the server itself.


0 comments::

Post a Comment

Copyright © DotNet-Ashok