namespace OA.Common
{
    public class PageSession : Page
    {
        public PageSession()
        {        }
        protected override void OnLoad(EventArgs e)
        {
           if (HttpContext.Current.Session["UserID"] == null)
           {
                string script = "<script>alert('请登陆!');</script>";
                HttpContext.Current.Response.Write("script");
                HttpContext.Current.Response.End();
                
            }
        }
      }
}然后现在有个页面Admin_SiteInfo : OA.Common.PageSession 继承这个基类,但是不起作用!!我就是想写个基类在基类里判断Session,然后其他所有页面继承这个基类.应该怎么写哦?谢谢了!!

解决方案 »

  1.   


    少了一个base.OnLoad(e);..如下namespace OA.Common
    {
        public class PageSession : Page
        {
            public PageSession()
            {        }
            protected override void OnLoad(EventArgs e)
            {
               if (HttpContext.Current.Session["UserID"] == null)
               {
                    string script = "<script>alert('请登陆!');</script>";
                    HttpContext.Current.Response.Write("script");
                    HttpContext.Current.Response.End();
                    
                }
                base.OnLoad(e);//加上这句
            }
          }
    }
      

  2.   

    HttpContext.Current.Response.Write("script");
    改成:
    HttpContext.Current.Response.Write(script);
      

  3.   

    我在本地改好测试通过..访问WebForm8.aspx..出现alert提示
    namespace WebApplication3
    {
        public class PageSession:Page
        {
            public PageSession()
            {        }
            protected override void OnLoad(EventArgs e)
            {
                if (HttpContext.Current.Session["UserID"] == null)
                {
                    string script = "<script>alert('请登陆!');</script>";
                    HttpContext.Current.Response.Write(script);
                    HttpContext.Current.Response.End();            }
            }    }
    }namespace WebApplication3
    {
        public partial class WebForm8 :PageSession
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               
            }
        }
    }
      

  4.   

            protected override void OnInit(EventArgs e)     //重写
            {
               
                if (Session["userName"] == null)
                {
                    string url = ConfigurationSettings.AppSettings["sysLoginPage"];
                    Response.Redirect(url);
                }
                base.OnInit(e);
            }