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

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

  • 相关阅读:
    docker 安装 clickhouse单机版
    CockRoachDB简介
    Ubuntu18.04 LTS Cockroach集群搭建
    ClickHouse 的一些优化参数
    ClickHouse 概念整理
    OOM Killer机制
    win10系统下载地址
    Quartz.Net在C#中的使用
    JavaScript的undefined与null、NaN的区别
    Java Web基础回顾 —JSP
  • 原文地址:https://www.cnblogs.com/ful1021/p/4804507.html
Copyright © 2011-2022 走看看