Is there a way to know the main/calling request in an httpmodule? I only want my module code to run for the main aspx page, not the images and scripts. I could check the path for ".aspx" but it seems like there should be a better way.
+3
A:
From your module you could call HttpContext.Current.Handler and see if it is a Page. You'd probably have to do this in the PostMapRequestHandler event or a later event in the life cycle.
Alternatively, maybe you can check which HttpHandlerFactory is being used for the request. If it is the PageHandlerFactory, you can run your logic, and otherwise you can skip it.
William Gross
2008-11-11 02:31:36
Checking CurrentHandler works and is ok if checked in the PreRequestHandler event. I am using spring.net so in my case it's the spring page handler. Checking that is similar to checking for the aspx extension but maybe this is a bit cleaner. Thanks
Marshal
2008-11-11 23:16:46
A:
IIS won't invoke the ASP.NET handler on images and scripts*, so a HTTPModule should only run on ASPX requests anyways.
- Unless you mean scripts served by as an embedded resource, ie webresource.axd.
FlySwat
2008-11-11 03:12:41
OP didn't clarify what version is he using. So the ASP.NET pipeline is invoked for every request? That seems silly.
FlySwat
2008-11-11 04:35:59
Yes it's invoked for every request (aspx and otherwise). At least it is on the visual studio integrated web dev server.
Marshal
2008-11-11 04:53:14
The Visual Studio integrated dev web server is nothing like IIS in production.
FlySwat
2008-11-11 10:09:02
It needs to work for IIS6, IIS7 and dev web server. That is irrelevant to the question.
Marshal
2008-11-11 22:56:45