为每个页面加上Session判断的小例子

首先新建一个类,继承自System.Web.UI.Page,然后重写OnInit,如下:


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace FuSession
{
    public class JudgeSession : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (Session.Keys.Count <= 0)
            {
                Response.Redirect("~/TiaoZh.htm", true);
            }
            else
            {
                if (Session["UserId"] == null && Session["Qx"] == null && Session["Dept"] == null && Session["UserName"] == null && Session["QxType"]==null)
                {
                    Response.Redirect("~/TiaoZh.htm", true);
                }
            }
        }      
    }
}

在页面中按照如下方法引用即可。


public partial class QrDeptMan_Home : FuSession.JudgeSession

若文章对您有帮助,帮忙点个赞!

0
0
发布时间 2013-10-22 15:55:31