登录:
string
username
=
txtusername.Text ;
string userpwd = txtuserpwd.Text ;
// 版本,关联的用户名,到期时间,发出时间,是否持久,自定义数据
System.Web.Security.FormsAuthenticationTicket ticket = new FormsAuthenticationTicket ( 1 ,username,DateTime.Now,DateTime.Now.AddMinutes( 1 ),
this .CheckBox1.Checked, " User " );
// 加密
string cookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie( " login " ,cookieStr);
if (CheckBox1.Checked)
{
cookie.Expires = ticket.Expiration;
}
Response.SetCookie(cookie);
Response.Redirect( " WebForm2.aspx " );
string userpwd = txtuserpwd.Text ;
// 版本,关联的用户名,到期时间,发出时间,是否持久,自定义数据
System.Web.Security.FormsAuthenticationTicket ticket = new FormsAuthenticationTicket ( 1 ,username,DateTime.Now,DateTime.Now.AddMinutes( 1 ),
this .CheckBox1.Checked, " User " );
// 加密
string cookieStr = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie( " login " ,cookieStr);
if (CheckBox1.Checked)
{
cookie.Expires = ticket.Expiration;
}
Response.SetCookie(cookie);
Response.Redirect( " WebForm2.aspx " );
登出:
System.Web.Security.FormsAuthentication.SignOut();
Response.Redirect("WebForm1.aspx");