您的位置:首页 > 其它

关于Form验证方式的cookie持久性问题

2010-01-08 15:35 573 查看
找到解决的方法是:authCookie.Expires = authTkt.Expiration;
http://dotnet.org.za/thea/archive/2004/07/27/3010.aspx I'm using Forms Authentication and Role based security for an app I'm working on. Ran into a problem that even though I set the IsPersistent parameter of the FormsAuthenticationTicket to true, next time I open the app I have to log in again...

authTkt =

new FormsAuthenticationTicket(1, userId, DateTime.Now, DateTime.Now.AddYears(1), true
, userRoles);

Well, doh, the plain and simple answer is that you need to set the expiry date of the cookie, otherwise it expires when the user closes the browser. Problem solved :-)

authCookie.Expires = authTkt.Expiration;

More info on ASP.Net cookies on CodeProject.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐