2011-03-24 236 views
0

我遇到问题。我使用cookies完成了自定义的“记住我”功能。Cookie登录不起作用

HttpCookie rememberMeCookie = FormsAuthentication.GetAuthCookie(userName, rememberMe); 
if (rememberMe) 
{ 
    rememberMeCookie.Expires = Controller.LocalizationProvider.GetAdjustedServerTime().AddMonths(6); 
} 

HttpContext.Current.Response.Cookies.Add(rememberMeCookie); 

我在Firefox中看到firecookies工具中的cookie。它存在且具有正确的到期日期。 但是当我改变时间 - 搬到下个月。之后,我进入了该网站,并取消了用户的登录。如果我回到现在的时间 - 我成为authothication用户。

回答

1

可能是formsauthentication timeout在您的web.config中存在干扰。下面是MSDN不得不说:

在ASP.NET V1.1永久性Cookie 不会超时,无论 设置超时属性的。 但是,从ASP.NET V2.0开始, 根据超时属性,永久性Cookie会超时 。