2

我正在这样做:

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);

网络配置:

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

我这样检查:

受保护的无效Application_OnPostAuthenticateRequest(对象发送者,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;
        }
    }

我究竟做错了什么?为什么它没有坚持很久?

4

0 回答 0