我想在下次登录页面
中选中“记住我”复选框时记住登录密码我有Set 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);
}
我使用mvc 4
谢谢你的帮助