【发布时间】:2009-11-08 02:31:25
【问题描述】:
我想知道如果用户在 10 分钟后没有执行任何请求,我该如何为用户设置超时,并且会话被终止并且他们被注销。
我的 webconfig 中有这个
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn"
protection="All"
timeout="20160"
path="/"
requireSSL="false"
slidingExpiration="false"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
我被告知将超时设置为“20160”,因为如果他们选中“保持登录状态 2 周”,我想登录 2 周。我还确保在我的 cookie Cookie 中启用 IsPersistent。
那么我需要设置另一个超时吗?由于在我的网站上闲置一段时间后,它不再起作用。我没有计时,但我说如果我离开并在 10 分钟后回来并尝试在我的网站上做一些事情,比如保存一些它不起作用的东西。所以看起来我的连接被杀死了。我必须退出,重新登录,然后它才能工作
编辑
这就是我制作饼干的方式
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(version,userName,DateTime.UtcNow,DateTime.UtcNow.AddDays(14),createPersistentCookie,userData,"/");
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
authCookie.Path = "/";
if (createPersistentCookie == true)
{
authCookie.Expires = DateTime.UtcNow.AddDays(14);
}
HttpContext.Current.Response.Cookies.Add(authCookie);
当我在我的 webconfig 中设置会话状态时,我的 url 中有这个
(S(gkvkze55zfzzee45wj34byee))
我宁愿在我的代码中没有这条讨厌的代码。
【问题讨论】:
-
关于 URL 中的 sessionID,您必须在 web.config 中将 cookieless="true" 更改为 "false"。通过这样做,您将不会在 URL 中拥有 SessionID。
标签: .net asp.net asp.net-mvc web-config