Fire events for requests to static content without setting runAllManagedModulesForAllRequests to true

为君一笑 提交于 2019-12-24 00:57:58

问题


I'm looking for a more precise solution to handle requests for static contents by the ASP.NET lifecycle without setting runAllManagedModulesForAllRequests to true. As far as I know is the effect of runAllManagedModulesForAllRequests = "true" that the precondition attribute of each module will be set to "".

The problem:

  • I have to protect static content in a subfolder of a web application against unauthorized access
  • To include requests to those static contents in the ASP.NET lifecycle and therefore having some events fired, I set runAllManagedModulesForAllRequests to true in web.config.
  • Because this solution turns the big wheel and all managed modules are affected for the whole application, I'm looking for a more adapted solution restricted to the subfolder where this behavior is required.
  • I need a solution for IIS6 and II7

Question 1:

The preconditon of which modules have to be resetted (precondition = "") to fire global.asax.cs events (e.g. Application_BeginRequest) for requests for static contents?

Question 2:

Is it possible to limit this request handling to requests to a single subfolder (e.g. perhaps by placing an adapted web.config in this subfolder, tweeking the main web.config, ...)

Any suggestions would be appreciated. Thanks.


回答1:


Have you thought in the direction of registering a custom HttpModule for the right event of global.asax, and then enabling the HttpModule only for the sub directory using location attribute in the main web.config itself? It is just a thought of a possible solution - I havent thought through it..

<location path="subDirectoryPath">
   <system.web>
     <httpmodules>
        <add type="MyCustomModule.Name" name="MyCustomModule" />      
     </httpmodules>
   </system.web>
</location>

EDIT:

You may have to override your web.config, and bring in all the httpModule section in this, and then insert the custom module at the right place, with the right precondition. This is to avoid setting runAllManagedModulesForAllRequests to true



来源:https://stackoverflow.com/questions/18999735/fire-events-for-requests-to-static-content-without-setting-runallmanagedmodulesf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!