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

找到解决的方法是: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.

posted on 2005-08-03 12:34  tangle  阅读(938)  评论(0编辑  收藏  举报