zoukankan      html  css  js  c++  java
  • Web开发 前台常用方法 BasePage类

        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");
            }
        }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Spring Boot2(九):整合Jpa的基本使用
    Spring Boot2(八):性感banner,在线发牌
    Spring Boot2(七):拦截器和过滤器
    我为什么要写作
    代码整洁之道
    redis-缓存穿透和缓存击穿
    云计算的三种服务模式
    java-泛型
    java-注解
    java-反射
  • 原文地址:https://www.cnblogs.com/ful1021/p/4804507.html
Copyright © 2011-2022 走看看