Determine HttpModule main/calling Request

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.


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.


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.
  • 链接地址: http://www.djcxy.com/p/43792.html

    上一篇: 子应用程序中的HttpModule无法加载类型

    下一篇: 确定HttpModule主/调用请求