i

ASP.Net A Complete Guide

Session State

Cookies:

 A cookie can store information such as ids, some frequent navigation, or post-back request objects. It is stored in the user's hard drive, and it uses the client's browser.

Server-Side State Management

In this technique, information stored in User memory. Below are the Server-Side techniques to save state:

Session: Normally, the session is used to store information and user's unique identity. The server stores "information" using "SessionId."

Session ["Name"] = Session ["Name"] + ":" + "Varsha"; //Set Value to The Session

Label2.Text = Session ["Name"]; //Get Value from the Session

Below are the session events:

Session_Start:

This event is raised every time a new user requests without a session ID.

void Session_Start(object sender, EventArgs e)

{

   Session ["Name"] = "Varsha';  // Code that runs when a new session is started

}

Session_End:This event is raised when the session is ended by a user, a time out expiry, or explicitly by using Session. Abandon () method. This event is raised only in the case "of In proc mode."

void Session_Start (object sender, EventArgs e)

{

   Session ["Name"] = "Varsha"; // Code that runs when a new session is started

}

There are four session mechanisms provided by ASP.NET:

InProcMode: It is a default session mode and a value stored in web server memory (IIS). Whenever the server starts, then the session value stored, and it ends when the server is restarted/stop.

State Server Mode: Information is stored in separate server.

SQL Server Mode: Information is stored in the database. It is a secure mode.

Custom Mode: If there is need to store session data using other than these techniques (nProc, SQL Server, State server) then ASP.NET provides a custom session mode