public class BasePage : System.Web.UI.Page { protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); if (Session["id"] == null || Session["loginId"] == null) { Response.Redirect("Login.aspx"); Response.End(); } } public int UserId { get { return Convert.ToInt32(Session["id"]); } } public string LoginId { get { return HttpUtility.UrlDecode(Session["loginId"].ToString()); } } public string Name { get { return HttpUtility.UrlDecode(Session["name"].ToString()); } } /// <summary> /// 退出登录 /// </summary> public void Logout() { HttpContext.Current.Session["id"] = null; HttpContext.Current.Session["loginId"] = null; HttpContext.Current.Session["name"] = null; HttpContext.Current.Session.Abandon(); if (HttpContext.Current.Request.Cookies["id"] != null) { CookieHelper.DelCookie("id"); } if (HttpContext.Current.Request.Cookies["loginId"] != null) { CookieHelper.DelCookie("loginId"); } if (HttpContext.Current.Request.Cookies["pwd"] != null) { CookieHelper.DelCookie("pwd"); } HttpContext.Current.Response.Redirect("/Login.aspx"); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。