2011-08-20 97 views
2

如何在ASP.NET中设置特定会话的超时时间?有可能的? 我有两个或两个以上sesions在我的web应用程序,我需要设置:设置特定会话的超时时间

Session["foo"] //expire in 14minutes 
Session["baa"] //expire in 30minutes 

我想解决这种情况下,如果可能的话不使用cookie。

在此先感谢!

+2

这些都不是不同的“会话”他们是不同的会话“变量”。用户一次只能有一个会话。 –

+2

也许您正在考虑缓存,您可以在其中设置每个项目的到期日期。 –

+0

@SteveWellens你能告诉如何为不同的变量设置超时 –

回答

2

您可以在Web.config文件中的会话配置超时:

<configuration> 
    <sessionstate mode="inproc" 
        cookieless="true" 
        timeout="14" /> 
</configuration> 

这是默认模式(InProc方式)为ASP.NET。正如rockinthesixtring在他的评论中所说的那样,你不能为会话中的单个对象配置超时,只是整个会话。

ASP.NET Session State Overview

-1
<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>