📄 masterpage.master.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Authentication;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["signOut"] == null)
btn_logout.Visible = true;
else
btn_logout.Visible = false;
}
}
protected void linkbtn_logout_Click(object sender, EventArgs e)
{
HttpCookie cookie = Response.Cookies[FormsAuthentication.FormsCookieName];
if (cookie != null)
{
FormsAuthentication.SignOut();//从浏览器删除 Forms 身份验证票证
}
Response.Cookies.Clear();//清空 Cookie 集合中的所有 Cookie
HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Value = null;
HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-100);
//HttpContext.Current.Session.Abandon();//取消当前 HttpContext 对象的会话
Session.Add("signOut", "true");
HttpContext.Current.Response.Redirect("~/Login.aspx");
}
protected void btn_Register_Click(object sender, EventArgs e)
{
Response.Redirect("~/Register.aspx");
}
protected void btn_Login_Click(object sender, EventArgs e)
{
Response.Redirect("~/Login.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -