繁体   English   中英

ASPX auth cookie到期时间始终为30分钟

[英]ASPX auth cookie expiration time is always 30 minutes

我已将cookie的到期时间设置为1个月,但是当我在浏览器中查看.ASPXAUTH cookie的到期超时时,它表示从现在开始提前30分钟。

var ticket = new FormsAuthenticationTicket(1, "myname", DateTime.Now,
                                                        DateTime.Now.AddMonths(1), true, "test");
string ticketString = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
                 {
                     Expires = DateTime.Now.AddMonths(1),
                     Path = FormsAuthentication.FormsCookiePath
                 };
HttpContext.Current.Response.Cookies.Add(cookie);

你能让我知道为什么上面的代码表现如此,我想改变过期时间,但总是要30分钟。

根据其他答案的建议,我得到了这个链接。

显然,在ASP.NET中,它会检查Web.config中的过期,并且不会从cookie中过期。 所以你需要添加到<system.web>里面的配置文件:

<authentication mode="Forms">
  <forms
 name=".ASPXAUTH"
 loginUrl="Login.cshtml" //your login page
 defaultUrl="Default.cshtml" //your default page
 protection="All" //type of encryption
 timeout="43200" //a month in minutes
 path="/"
 requireSSL="false"
 slidingExpiration="true" //Every refresh the expiration time will reset
 cookieless="UseDeviceProfile" //Use cookies if the browser supports cookies
 domain=""
 enableCrossAppRedirects="false">
    <credentials passwordFormat="SHA1" />
  </forms>
</authentication>

您是否需要以编程方式设置此超时,还是可以在配置文件中设置它? 有一个超时参数,表示身份验证cookie超时: http//msdn.microsoft.com/en-us/library/1d3t3c61.aspx

此参数的默认值为30分钟。

最好的问候,德米特里

检查你的web.config文件,下面的元素system.web - > authentication下应该有FORM条目。

检查那里的超时属性,是否设置为30分钟?

从那里删除此表单身份验证标记。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM