随笔-19  评论-6  文章-5  trackbacks-0

关于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 阅读(526) 评论(0) 编辑 收藏
昵称:tangle
园龄:7年9个月
粉丝:14
关注:32
<2005年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

搜索

 
 

常用链接

随笔分类

随笔档案

最新评论

阅读排行榜

评论排行榜

推荐排行榜