zoukankan      html  css  js  c++  java
  • 利用自定义类来管理网站用户登陆session版

    以前做asp的时候可以建一个文件然后写入判断session中的成员是否存在的语句,然后再include在管理员或会员要登陆的页中,现在做asp.net了也想了一个类似一个同样的方法。希望大家交流~~

    实现方法:

    一、自定义 SessionUser类
    /// <summary>
    /// SessionUser类 的摘要说明
    /// </summary>
    public class SessionUser
    {
        public SessionUser()
        {     
            if (HttpContext.Current.Session["user"] == null)
            {
                HttpContext.Current.Response.Write("<script>alert('对不起请你登陆!')</script>");
                HttpContext.Current.Response.Write("('对不起请你登陆!')");
                HttpContext.Current.Response.End();
            }
        }
    }

    二、调用文件中的Page_Loa方法来实例化

    protected void Page_Load(object sender, EventArgs e)
    {
       SessionUser login = new SessionUser();
    }

  • 相关阅读:
    二 、异常
    Java的基本概念
    Oracle case when
    oracle exists
    一 、前言
    location
    HTTP1.1初识
    数学学习笔记(持续更新中)
    [NOIP2017 提高组] 列队 题解
    [NOI2019] 回家路线 题解
  • 原文地址:https://www.cnblogs.com/astar/p/851150.html
Copyright © 2011-2022 走看看