FormsAuthenticationTicket Ticket = Id.Ticket ; //取得身份验证票
string userName=Ticket.Name;
或者string userName=User.Identity.Name;
if (FormsAuthentication.GetRedirectUrl(userName, false).EndsWith("default.aspx"))
{
//FormsAuthentication.SetAuthCookie(userName, persist.Checked);
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1,userName,DateTime.Now,DateTime.Now.AddMinutes(20),persist.Checked, role);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //加密
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
HttpContext.Current.Response.Redirect("default.aspx", true);
}
else
{
//FormsAuthentication.SetAuthCookie(userName, persist.Checked);
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1,userName,DateTime.Now,DateTime.Now.AddMinutes(20),persist.Checked, role);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //加密
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, false), true);
}