Asp.net mvc 4 下次登录MVC4时,通过选中记住我来记住密码

Asp.net mvc 4 下次登录MVC4时,通过选中记住我来记住密码,asp.net-mvc-4,authorization,remember-me,httpcookie,Asp.net Mvc 4,Authorization,Remember Me,Httpcookie,我想在下次登录时记住密码,请在登录页面中选中“记住我”复选框 我有这个方法来设置AuthCookie private void SetAuthCookie(string userName, string roleofUser, bool presistantCookie) { double timeout = presistantCookie ? FormsAuthentication.Timeout.TotalMinutes : 30;

我想在下次登录时记住密码,请在登录页面中选中“记住我”复选框

我有这个方法来设置AuthCookie

private void SetAuthCookie(string userName, string roleofUser, bool presistantCookie)
        {
            double timeout = presistantCookie ? FormsAuthentication.Timeout.TotalMinutes : 30;

            DateTime now = DateTime.UtcNow.ToLocalTime();
            TimeSpan expirationTimeSapne = TimeSpan.FromMinutes(timeout);

            var authTicket = new FormsAuthenticationTicket(
                1,
                userName,
                now,
                now.Add(expirationTimeSapne),
                presistantCookie,
                roleofUser,
                FormsAuthentication.FormsCookiePath
                );

            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

            var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true,
                Secure = FormsAuthentication.RequireSSL,
                Path = FormsAuthentication.FormsCookiePath
            };

            if (FormsAuthentication.CookieDomain != null)
            {
                authCookie.Domain = FormsAuthentication.CookieDomain;
            }

            if (presistantCookie)
                authCookie.Expires = DateTime.Now.AddMinutes(timeout);
            Response.Cookies.Add(authCookie);

        }
我和MVC4一起工作

谢谢你的帮助