How I can set the timeout for a session specific in ASP.NET? it is possible? I have two or more sesions in my web application, I need set:
Session[\"foo\"] //exp
<sessionState
mode="InProc"
stateNetworkTimeout="10" //seconds
cookieless="UseCookies"
cookieName="ASP.NET_SessionId" //Specifies the name of the cookie that stores the session identifier.
timeout="20" //seconds
regenerateExpiredSessionId="true"
useHostingIdentity="true">
</sessionState>
or
session["user"]=textbox_username.txt
<configuration>
<system.web>
<sessionState cookieless="true"
regenerateExpiredSessionId="true" />
</system.web>
</configuration>
Since other questions are being closed as duplicates of this question I would like to add this option here for people who may find it useful.
You can set the Session Timeout manually using the following:
Session.Timeout = 60
You can read more here:
https://msdn.microsoft.com/en-us/library/ms525473(v=vs.90).aspx
You can configure the timeout for a session in the Web.config file:
<configuration>
<sessionstate mode="inproc"
cookieless="true"
timeout="14" />
</configuration>
This is the default mode (InProc) for ASP.NET. As rockinthesixtring said in his comment, you can't configure the timeout for individual objects in the session, just the session as a whole.
ASP.NET Session State Overview
for specific session lets say you want to make timeout for this session Session["foo"] =14 min you can do like this
DateTime timenow=DateTime.now;
DateTime timeafter14min=timenow.AddMinuits(14);
if(DateTime.Now>timeafter14min)
{
HttpContext.Current.Session["foo"]=null;
}
session not expired but cleared