【问题标题】:Why does a reverse proxy rewrite rule stop working when System.Web.Routing is active?为什么当 System.Web.Routing 处于活动状态时,反向代理重写规则停止工作?
【发布时间】:2012-04-08 03:12:17
【问题描述】:

将其归结为最简单的规则:

      <rule name="Reverse Proxy" stopProcessing="true">
          <match url="^external/(.*)" />
          <action type="Rewrite" url="http://some-site/{R:1}" />
      </rule>

(“启用代理”在服务器级别的 ARR 服务器代理设置中选中)。

上面的重写规则在一个非常简单的测试应用程序中运行良好,其中 web.config 包含该部分,它在 Web 表单应用程序中运行良好,但如果我将相同的规则放入 MVC3 应用程序(在同一台机器上,所以更高的 IIS 配置相同)它永远不会有任何效果;请求通过。

如果它只是重​​写(而不是反向代理),它可以正常工作,例如,

          <rule name="rewrite to internal" stopProcessing="true">
              <match url="^internal/(.*)" />
              <action type="Rewrite" url="different-internal/{R:1}" />
          </rule>

...很好。

如果我添加,我可以让反向代理规则工作

        routes.IgnoreRoute("external/{*pathInfo}");

在 Global.asax.cs 类中,这样我对 external/* 的请求就不会命中默认控制器,但我不明白为什么。我认为 URL 重写模块在路由之前启动(参见 http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/),所以我希望它们之间不会发生冲突。

路由模块是否在 URL 重写模块中添加了“虚拟”重写规则,从而覆盖了我声明的重写规则?

【问题讨论】:

    标签: iis-7 url-rewriting asp.net-mvc-routing


    【解决方案1】:

    我也遇到了同样的问题,我花了一整天的时间才找到the solution.

    1. 在您的 Web.config 文件中找到 ServoceModel 标记并添加 serviceHostingEnvironment 代码,如下所示:

            <system.serviceModel>
              <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
            </system.serviceModel>
      

    这将允许将路由传递给 IIS 来处理它。

    还有一个提示,我建议任何在 MVC 项目中遇到路由问题的人通过 NuGet 安装 Remote Debugger。这将告诉您什么时候激活了哪些路由。

    【讨论】:

    • 不能真正使用 aspNetCompatibilityEnabled=true,因为它有缺点,但是 OP 的 IgnorePath +1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多