user login logout

 protected void LoginButton_Click(object sender, EventArgs e)
    {
        username 
= Guid.NewGuid().ToString();
        Response.Write(username);
        FormsAuthenticationTicket ticket 
= new FormsAuthenticationTicket(username, true20);
        
string cookiestr = FormsAuthentication.Encrypt(ticket);
        HttpCookie ck 
= new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
        
if (true)
        {
            ck.Path 
= FormsAuthentication.FormsCookiePath;
        }
        Response.Cookies.Add(ck);
        FormsAuthentication.RedirectFromLoginPage(username, 
false);
    }
    
protected void LogoutButton_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect(
"Default.aspx");
    }
原文地址:https://www.cnblogs.com/sskset/p/1289723.html