web version of the user login bills FormsAuthenticationTicket

= New new Ticket the FormsAuthenticationTicket the FormsAuthenticationTicket (. 1, "username", the DateTime.Now, DateTime.Now.AddDays (365),
to true, string.Format ( "{0}: {}. 1", "username", "password"), FormsAuthentication.FormsCookiePath);
// here string.Format ( "{0}: { 1}", "username", "password"), may be changed to any value, such as a password or the IP
String ticString = FormsAuthentication.Encrypt (ticket);
// bills encrypted saved as the cookie
HttpCookie new new COO = HttpCookie (FormsAuthentication.FormsCookieName, ticString);
// isPersistent here do not judge their own, require manual judgment, but the value of the expiration of FormsAuthenticationTicket is to have expired property, regardless of how long the cookie expires provided, as long as the expiration expires, even if there is a user authentication cookie will fail
IF (ticket.IsPersistent)
{
coo.Expires = ticket.Expiration;
}
// use by adding a new cookie userdata of
Response.Cookies.Add (coo);
//FormsAuthentication.SetAuthCookie("username ", true); // This wording is fast, with such an approach can not build their own ticket bills, you can not use the UserData parameters


Cookie //FormsAuthentication.SignOut// to clear this flag //FormsAuthentication.RedirectFromLoginPage(userID, createPersistentCookie);

// <authentication mode="Forms">
// <forms name=".MyCookie" loginUrl="Login.aspx" protection="All" timeout="60"/>
// </authentication>

Guess you like

Origin www.cnblogs.com/zhuqun/p/12035020.html