Question

I have a piece of code that is preprocessing submitted form. Currently it was copy/paste solution, but now as I'm using basically the same code on three pages I wanted to encapsulate it. By first thought was to do it using IHttpModule. The only question is: how to register this module only for a few pages, so I could do my stuff in BeginRequest event handler.

Was it helpful?

Solution

ASP.NET HttpModule is attached to the processing pipeline itself so all requests go through this and you have to check for the request you want to handle. For the requirement you have, HttpHandler might be a better choice. Put all the selected pages in a single folder and register the HttpHandler like this.

<add verb="*" path="/selected/*.aspx" type="YourHandler,Assembly"/> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top