过滤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);
}
}

原文地址:https://www.cnblogs.com/jinhaoObject/p/4532865.html