利用自定义类来管理网站用户登陆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();
}

原文地址:https://www.cnblogs.com/astar/p/851150.html