我想对每个页面都判断一下是否登陆,网上找的方法是加一个BasePage类,然后再加到每个页面上,但是总是404错误,求解决办法??
BasePage类: public class BasePage : System.Web.UI.Page
{
public BasePage()
{
this.Load += new EventHandler(BasePage_Load);
}
void BasePage_Load(object sender, EventArgs e)
{
if (Session["username"] == null||Session["username"].ToString().Equals(" "))
{
Response.Write("<script>alert('请先登录!');window.location='../Default.aspx';</script>");
}
} }在调用页面的CS中写了:
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
..........
}
}
怎么办呢???
BasePage类: public class BasePage : System.Web.UI.Page
{
public BasePage()
{
this.Load += new EventHandler(BasePage_Load);
}
void BasePage_Load(object sender, EventArgs e)
{
if (Session["username"] == null||Session["username"].ToString().Equals(" "))
{
Response.Write("<script>alert('请先登录!');window.location='../Default.aspx';</script>");
}
} }在调用页面的CS中写了:
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
..........
}
}
怎么办呢???
return;
啊,或者
System.Web.HttpContext.Current.Response.End();最好
System.Web.HttpContext.Current.Response.Redirect("~/Default.aspx");