I have an http module on a sharepoint site and this module instantiates a custom class and add it to the session and does other initial things for my site. However, I'm noticing that the http module is being called for all request types (.aspx, .js, .png, .jpg).

Is there any way to have an http module only be called for .net specific page types?


Thanks for your answer, but the suggestion is to use a handler, or look at the path of the request and bypass the validation.

In my situation, I cannot use a handler and what I'm looking to do is prevent any handler events from being fired for js pages.

Is this possible?


In IIS you will set up the handler to be associated with your specific extension so the handler will only be applied to that extension. JavaScript files should not be processed.

Ryan Montgomery

I would also have a look at this article is you are looking at integrating your module/handler with SharePoint in any way.

Ryan Montgomery
Ryan Montgomery

I've done a bit more research and it seems there is no way to do what I'm intending. I will have to check the request type and cancel from there.

Thanks everyone for their answers.



You can do this in a very lightweight manner using a HttpModule (before making any calls to the expensive SharePoint object model) by checking the extension in the content of the last Uri.Segments

void context_BeginRequest(object sender, EventArgs e)
    HttpApplication app = (HttpApplication)sender;
    Uri uri = app.Request.Url;
    string lastSegment = uri.Segments[uri.Segments.Length-1];
    .. check your extension here an do nothing if it doesn't match.

We use this in our 'TinyURL' implementation for SharePoint to ensure the performance impact for regular URLs is almost 0.