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

发布于 2024-07-28 22:46:08 字数 1208 浏览 5 评论 0原文

我有一个非常简单的自定义身份验证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="managementHandler",但由于有 runAllManagedModulesForAllRequests="true" > 在父 元素上,我的 preCondition 被设计忽略(正如我在 MSDN 上读到的那样)。

当我尝试设置时:

<modules runAllManagedModulesForAllRequests="false">

我收到错误。

我还必须在 web.config 中设置什么(其他模块)才能使此设置起作用:

<modules runAllManagedModulesForAllRequests="false">

I have a custom authentication HttpModule that is pretty strait forward. But I want it to run only for managed requests (and not for static ones).

Asp.net MVC automatically adds configuration section for IIS7 web server:

<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>

When I add my own module I also set its preCondition="managedHandler", but since there's runAllManagedModulesForAllRequests="true" on parent <module> element my preCondition is ignored by design (as I read on MSDN).

When I try to set though:

<modules runAllManagedModulesForAllRequests="false">

I get an error.

What else (which other module) do I have to set in web.config to make this setting work:

<modules runAllManagedModulesForAllRequests="false">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友欢 2024-08-04 22:46:08

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

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

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

I think you’ve got the error message because your application was relying on some other managed module (Session) and that module was configured to run only for requests to managed handler (runAllManagedModulesForAllRequests="false").

You can try the following setting to Re-configure the Session module to run for all requests

<modules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
</modules>
晚风撩人 2024-08-04 22:46:08

好的。 所以我有一个解决方案和解决方法。
我仍然必须使用默认模块设置:

<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 配置的解决方案。

Ok. So I have a solution with a workaround for this.
I still had to use default modules setting as:

<modules runAllManagedModulesForAllRequests="true">

But I was able to disable my custom authentication module by setting additional web.config entries for certain locations like:

<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>

So I disabled authentication on certain paths. It's a workaround and not an actual solution. So you can still provide your own suggestions or even solutions that actually address the runAllManagedModulesForAllRequests="true" default Asp.net MVC configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文