过滤asp.net页面每次发出请求之前访问

public class PageFiltert : System.Web.UI.Page
{
public PageFiltert()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
protected override void OnPreInit(EventArgs e)
{
//context.PostRequestHandlerExecute += new EventHandler(this.Application_beginRequest);
//this.OnPreInit += new System.EventHandler(Application_beginRequest);
//this.Load += new System.EventHandler(Application_beginRequest);
if (!Page.IsPostBack)
{
if (HttpContext.Current.Session["userName"] == null)
{
HttpContext.Current.Response.Write("<script>window.parent.location.href='../../login.aspx'</script>");//必须是根目录
Response.End();
//HttpContext.Current.Response.Redirect("~/login.aspx");
}
}
base.OnPreInit(e);
}
}

posted @ 2015-05-27 11:06  caijinhao  阅读(476)  评论(0编辑  收藏  举报