排除某些网页使用一个HTTP模块模块、网页、HTTP

2023-09-02 01:50:13 作者:眉眼带笑

有没有排除使用一个HTTP模块某些网页的好办法?

Is there a good way to exclude certain pages from using a HTTP module?

我有一个使用自定义的HTTP模块来验证会话的应用程序。该HTTP模块设置这样的web配置:

I have an application that uses a custom HTTP module to validate a session. The HTTPModule is set up like this in web config:

<system.web>
  <!-- ... -->
  <httpModules>
    <add name="SessionValidationModule"
       type="SessionValidationModule, SomeNamespace" />
  </httpModules>
</system.web>

要排除的页面模块,我试图做这个(没有成功):

To exclude the module from the page, I tried doing this (without success):

<location path="ToBeExcluded">
  <system.web>
    <!-- ... -->
    <httpModules>
      <remove name="SessionValidationModule" />
    </httpModules>
  </system.web>
</location>

有什么想法?

推荐答案

您可以使用一个HttpHandler,而不是一个HTTP模块。处理程序允许您指定的路径,当你在Web.Config中声明它们。

You could use an HTTPHandler instead of an HTTPModule. Handlers let you specify a path when you declare them in Web.Config.

<add verb="*" path="/validate/*.aspx" type="Handler,Assembly"/>

如果必须使用HTTP模块,你可以只检查请求的路径,如果它是一个被排除在外,绕过验证。

If you must use an HTTPModule, you could just check the path of the request and if it's one to be excluded, bypass the validation.