C# 如何确保不从asp.net中的特定文件调用http模块

C# 如何确保不从asp.net中的特定文件调用http模块,c#,asp.net,C#,Asp.net,我有一个网站下,我有5个文件 test1.aspx test2.aspx test3.aspx test4.aspx test5.aspx 我有一个http模块,它在所有页面中都被调用 但是我有一个条件,在test5.aspx页面上,我不希望调用http模块。为了解决这个问题,需要进行哪些设置?HttpModules在页面生命周期之前运行,因此您必须在请求路径上匹配它 假设您的HttpModule的Init函数设置了一个BeforeRequest处理程序,类似于: public class My

我有一个网站下,我有5个文件

  • test1.aspx
  • test2.aspx
  • test3.aspx
  • test4.aspx
  • test5.aspx
  • 我有一个http模块,它在所有页面中都被调用
    但是我有一个条件,在test5.aspx页面上,我不希望调用http模块。为了解决这个问题,需要进行哪些设置?

    HttpModules在页面生命周期之前运行,因此您必须在请求路径上匹配它

    假设您的HttpModule的
    Init
    函数设置了一个
    BeforeRequest
    处理程序,类似于:

    public class MyModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.BeginRequest += this.BeginRequest;
        }
    
        public void BeginRequest(object sender, EventArgs e)
        {
            var app = sender as HttpApplication;
            if (app.Request.Path.Contains("test5.aspx")) {
                return;
            }
    
            // Process logic for other pages here
        }
    }
    

    HttpModules在页面生命周期之前运行,因此您必须在请求路径上匹配它

    假设您的HttpModule的
    Init
    函数设置了一个
    BeforeRequest
    处理程序,类似于:

    public class MyModule : IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.BeginRequest += this.BeginRequest;
        }
    
        public void BeginRequest(object sender, EventArgs e)
        {
            var app = sender as HttpApplication;
            if (app.Request.Path.Contains("test5.aspx")) {
                return;
            }
    
            // Process logic for other pages here
        }
    }