表单身份验证“记住我”不记得我

时间:2012-04-06 09:38:03

标签: asp.net forms-authentication

我这样做:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, model.UserName,
                                DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes),
                                model.RememberMe, verification.UserId.ToString());
                            string hashedTicket = FormsAuthentication.Encrypt(ticket);

的web.config:

  <authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" defaultUrl="/" name="FunkyAuth" timeout="10000" />
  </authentication>

我这样检查:

  

protected void Application_OnPostAuthenticateRequest(object sender,EventArgs e)   {

HttpCookie formsCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

        if (formsCookie != null)
        {
            FormsAuthenticationTicket auth = FormsAuthentication.Decrypt(formsCookie.Value);

            if (string.IsNullOrWhiteSpace(auth.UserData)) return;

            int userId = int.Parse(auth.UserData);

            var principal = new FunkyPrincipal(new GenericIdentity(auth.Name), userId);

            Context.User = principal;
            Thread.CurrentPrincipal = principal;

            //Response.Cookies[FormsAuthentication.FormsCookieName] = formsCookie;
        }
    }

我做错了什么?为什么它长时间没有坚持下去?

0 个答案:

没有答案