62,046
社区成员
发帖
与我相关
我的任务
分享
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".AuthKey" defaultUrl="Default.aspx" cookieless="UseCookies" slidingExpiration="false"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
protected void btnLogin_Click(object sender, EventArgs e)
{
var isPersistent = false;
FormsAuthentication.SetAuthCookie("admin", isPersistent);
this.Response.Redirect(FormsAuthentication.DefaultUrl);
}
protected void Page_Load(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
//清除客户端的Cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
Session.Abandon();
//重置登录身份(没效果)
HttpContext.Current.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
}