Question

I have a class that implements IHttpModule. This is a support class to help my application defend against DDOS attacks. After implementing the BeginRequest method, I tried to debug my code and for some reason, each time that I debug the class, I have multiple threads in Visual studio. I can't understand why, all of the sudden, while running this application on my local machine, I'm getting several threads, and it happens only in this class.

Was it helpful?

Solution

The HttpModule probably intercepts all requests to your application, including files (js, css, images, etc.)

Take a look at the Request object of each request, and look at the Url property to see what is happening.

Edit: HttpModules are active very early in the request flow, and they will often get hit by most requests for the server, so keep the code in the HttpModule to a minimum. An example: if you're making permissions on files, make sure the request is actually hitting a file (ie. the requested url starts with /files/). Whenever possible, cache data for use in HttpModules, don't go to the database for each and every request in a HttpModule!

The reason why you probably get less hits in your actual application, is that even requests for images, js files, css files, etc. might make a hit in the HttpModule, but in your application, only requests meant for the application will hit your break points (aspx, asmx, etc. for Web Forms and recognized routes in ASP.NET MVC).

To get a look at what requests you're handling in a HttpModule, look at the value of the url variable:

void context_BeginRequest(object sender, EventArgs e) {
    HttpApplication app = (HttpApplication)sender;
    String url = app.Request.Url.OriginalString;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top