


只需要配置一个preCondition="managedHandler"即可
<system.webServer> <modules> <add name="MyModule" type="MyNamespace.MyModule" preCondition="managedHandler" /> </modules> </system.webServer>
加上了preCondition="managedHandler"这个配置项后,在IIS7的集成模式下,
上面自定义的MyModule这个HttpModule就不会去处理静态文件(.html .css .js .jpeg等)的请求了,
只会处理托管文件(aspx, ascx 及 MVC等)的请求。
此外在<system.webServer>的<modules>节点上还有个配置项叫runAllManagedModulesForAllRequests如下面代码所示:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="MyModule1" type="MyNamespace.MyModule1" preCondition="managedHandler" /> <add name="MyModule2" type="MyNamespace.MyModule2" preCondition="managedHandler" /> <add name="MyModule3" type="MyNamespace.MyModule3" preCondition="managedHandler" /> <add name="MyModule4" type="MyNamespace.MyModule4" preCondition="managedHandler" /> <add name="MyModule5" type="MyNamespace.MyModule5" /> </modules> </system.webServer>
如果你将runAllManagedModulesForAllRequests设置为true,那么ASP.NET就会忽略<modules>所有子节点的preCondition设置
,相当于上面代码中MyModule1、MyModule2、MyModule3和MyModule4都没有设置preCondition="managedHandler",
MyModule1到MyModule5仍然会处理静态文件(.html .css .js .jpeg等)的请求,
所以runAllManagedModulesForAllRequests相当于是一个快捷设置,可以关闭<modules>所有子节点的preCondition设置
,强制使所有自定义的HttpModule既处理静态文件(.html .css .js .jpeg等)请求又处理托管文件(aspx, ascx 及 MVC等)请求,
默认情况下runAllManagedModulesForAllRequests是为false的。
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)