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,然后其他所有页面继承这个基类.应该怎么写哦?谢谢了!!
少了一个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);//加上这句
}
}
}
改成:
HttpContext.Current.Response.Write(script);
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)
{
}
}
}
{
if (Session["userName"] == null)
{
string url = ConfigurationSettings.AppSettings["sysLoginPage"];
Response.Redirect(url);
}
base.OnInit(e);
}