如何在ASP.NET中设置特定会话的超时时间?有可能的? 我有两个或两个以上sesions在我的web应用程序,我需要设置:设置特定会话的超时时间
Session["foo"] //expire in 14minutes
Session["baa"] //expire in 30minutes
我想解决这种情况下,如果可能的话不使用cookie。
在此先感谢!
如何在ASP.NET中设置特定会话的超时时间?有可能的? 我有两个或两个以上sesions在我的web应用程序,我需要设置:设置特定会话的超时时间
Session["foo"] //expire in 14minutes
Session["baa"] //expire in 30minutes
我想解决这种情况下,如果可能的话不使用cookie。
在此先感谢!
您可以在Web.config文件中的会话配置超时:
<configuration>
<sessionstate mode="inproc"
cookieless="true"
timeout="14" />
</configuration>
这是默认模式(InProc方式)为ASP.NET。正如rockinthesixtring在他的评论中所说的那样,你不能为会话中的单个对象配置超时,只是整个会话。
<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>
由于其他问题都被关闭,因为这个问题,我想在此补充这个选项的人谁可能会发现它很有用的副本。
您可以设置会话超时使用手动如下:
Session.Timeout = 60
你可以在这里阅读更多:
https://msdn.microsoft.com/en-us/library/ms525473(v=vs.90).aspx
这些都不是不同的“会话”他们是不同的会话“变量”。用户一次只能有一个会话。 –
也许您正在考虑缓存,您可以在其中设置每个项目的到期日期。 –
@SteveWellens你能告诉如何为不同的变量设置超时 –