配置托管模块的Asp.net MVC错误

时间:2009-07-21 19:45:17

标签: asp.net-mvc iis-7 web-config httpmodule

我有一个相当严格的自定义身份验证HttpModule。但是我希望它只针对托管请求运行(而不是针对静态请求)。

Asp.net MVC自动为IIS7 Web服务器添加配置部分:

<system.webServer>
   <validation validateIntegratedModeConfiguration="false" />
   <modules runAllManagedModulesForAllRequests="true">
      <remove name="ScriptModule" />
      <remove name="UrlRoutingModule" />
      <add name="ScriptModule"
           preCondition="managedHandler"
           type="System.Web.Handlers.ScriptModule,..." />
      <add name="UrlRoutingModule"
           type="System.Web.Routing.UrlRoutingModule,..." />
   </modules>
   <handlers>
      ...
   </handlers>
</system.webServer>

当我添加自己的模块时,我也设置了preCondition="managedHandler",但由于父runAllManagedModulesForAllRequests="true"元素上有<module>,我的preCondition被设计忽略(正如我读到的那样) MSDN)。

当我尝试设置时:

<modules runAllManagedModulesForAllRequests="false">

我收到错误。

我需要在web.config中设置其他(其他模块)以使此设置有效:

<modules runAllManagedModulesForAllRequests="false">

2 个答案:

答案 0 :(得分:3)

我认为您收到了错误消息,因为您的应用程序依赖于其他托管模块(Session),并且该模块配置为仅针对托管处理程序的请求运行(runAllManagedModulesForAllRequests =“false”)。

您可以尝试以下设置重新配置会话模块以针对所有请求运行

<modules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
</modules>

答案 1 :(得分:2)

确定。所以我有一个解决方案,为此解决方法。 我仍然必须使用默认模块设置为:

<modules runAllManagedModulesForAllRequests="true">

但我可以通过为某些位置设置其他web.config条目来禁用我的自定义身份验证模块,如:

<location path="~/App_Themes">
    <system.web>
        <authentication mode="None" />
    </system.web>
</location>

<location path="~/Content">
    <system.web>
        <authentication mode="None" />
    </system.web>
</location>

<location path="~/Scripts">
    <system.web>
        <authentication mode="None" />
    </system.web>
</location>

所以我在某些路径上禁用了身份验证。这是一种解决方法,而不是一个实际的解决方案。因此,您仍然可以提供自己的建议,甚至是实际解决runAllManagedModulesForAllRequests="true"默认Asp.net MVC配置的解决方案。

相关问题