protected void Page_Load(object sender, EventArgs e)
{
Session["lv"] = DateTime.Now;
if (Session["lv"] != null)
{
Label1.Text = Session["lv"].ToString();
}
else
{
Label1.Text = "No information about the last visit of the user";
}
}
If we don't want to use the Session state, we can improve performance by disabling the session state for the entire application by setting the SessionState property to Off in the Web.config file:
<configuration>
<system.web>
<sessionState mode="Off" />
</system.web>
</configuration>
If we want to disable session for the particular page of an application setEnableSessionState="False". We can also set EnableSessionState page directive to ReadOnly to provide readonly access to the session variable.
By default, Session state uses cookies to track user sessions. The following example shows that how we use the cookieless session identifiers:
<configuration>
<system.web>
<sessionState cookieless="true" regenerateExpiredSessionId="true" />
</system.web>
</configuration>

Join the conversation! Your thoughts help the community grow.