2009-07-21 36 views
2

我有一个自定义身份验证HttpModule,这是非常海峡。但我希望它只能运行托管的请求(而不是静态的)。配置托管模块的Asp.net MVC错误

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",但由于上级<module>元素有runAllManagedModulesForAllRequests="true"preCondition被设计忽略(正如我在MSDN上读到的)。

当我尝试设置虽然:

<modules runAllManagedModulesForAllRequests="false"> 

我得到一个错误。

还有什么(这等模块),我要在web.config设置此设置工作:

<modules runAllManagedModulesForAllRequests="false"> 

回答

3

我想你已经得到了错误消息,因为您的应用程序依赖一些其他管理模块(Session),并且该模块被配置为仅对托管处理程序的请求运行(runAllManagedModulesForAllRequests =“false”)。

你可以试试下面的设置会话模块重新配置,为所有请求

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

谢谢彼得。事情是我将所有preConditions定义为managedHandler。它的工作。 – 2009-07-22 16:10:41

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> 

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