<p>Is there a good way to exclude certain pages from using a HTTP module?</p>

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

<pre><code>&lt;system.web&gt;
  &lt;!-- ... --&gt;
  &lt;httpModules&gt;
    &lt;add name="SessionValidationModule"
       type="SessionValidationModule, SomeNamespace" /&gt;
  &lt;/httpModules&gt;
&lt;/system.web&gt;
</code></pre>

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

<pre><code>&lt;location path="ToBeExcluded"&gt;
  &lt;system.web&gt;
    &lt;!-- ... --&gt;
    &lt;httpModules&gt;
      &lt;remove name="SessionValidationModule" /&gt;
    &lt;/httpModules&gt;
  &lt;/system.web&gt;
&lt;/location&gt;
</code></pre>

<p>Any thoughts?</p>

[{'answer_id': 71790, 'author': 'Crob', 'author_id': 2460, 'author_profile': 'https://Stackoverflow.com/users/2460', 'pm_score': 5, 'selected': True, 'text': '<p>You could use an HTTPHandler instead of an HTTPModule.  Handlers let you specify a path when you declare them in Web.Config.  </p>\n\n<pre><code>&lt;add verb="*" path="/validate/*.aspx" type="Handler,Assembly"/&gt;\n</code></pre>\n\n<p>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.  </p>\n'}, {'answer_id': 72823, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>HttpModules attach to the ASP.NET request processing pipeline itself. The httpModule itself must take care of figuring out which requests it wants to act on and which requests it wants to ignore. </p>\n\n<p>This can, for example, be achieved by looking at the context.Request.Path property.</p>\n'}, {'answer_id': 18411217, 'author': 'Mr. Pumpkin', 'author_id': 524605, 'author_profile': 'https://Stackoverflow.com/users/524605', 'pm_score': 3, 'selected': False, 'text': '<p>Here is some simple example how to filter requests by extension... the example below exclude from the processing files with the specific extensions. Filtering by file name will look almost the same with some small changes...</p>\n\n<pre><code>public class AuthenticationModule : IHttpModule\n{\n    private static readonly List&lt;string&gt; extensionsToSkip = AuthenticationConfig.ExtensionsToSkip.Split(\'|\').ToList();\n\n    // In the Init function, register for HttpApplication \n    // events by adding your handlers.\n    public void Init(HttpApplication application)\n    {\n        application.BeginRequest += new EventHandler(this.Application_BeginRequest);\n        application.EndRequest += new EventHandler(this.Application_EndRequest);\n    }\n\n    private void Application_BeginRequest(Object source, EventArgs e)\n    {\n        //  we don\'t have to process all requests...\n        if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath)))\n            return;\n\n        Trace.WriteLine("Application_BeginRequest: " + HttpContext.Current.Request.Url.AbsoluteUri);\n    }\n\n    private void Application_EndRequest(Object source, EventArgs e)\n    {\n        //  we don\'t have to process all requests...\n        if (extensionsToSkip.Contains(Path.GetExtension(HttpContext.Current.Request.Url.LocalPath)))\n            return;\n\n        Trace.WriteLine("Application_BeginRequest: " + HttpContext.Current.Request.Url.AbsoluteUri);\n    }\n}\n</code></pre>\n\n<p>General idea is to specify in config file what exactly should be processed (or excluded from the processing) and use that config parameter in the module.</p>\n'}]
['https://Stackoverflow.com/questions/70956', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6308/']