使用IIS应用程序请求路由(ARR)实现ASP。NET MVC

时间:2020-12-28 03:34:34

I use a simple ASP.NET MVC web (the template you use when you create a new site) and the web works as expected in my live environment.

我使用一个简单的ASP。NET MVC web(创建新站点时使用的模板)和web在我的活动环境中正常工作。

I now try to use IIS Application Request Routing version 2. I have a rule that send all requests to a different server that match a rule.

我现在尝试使用IIS应用程序请求路由版本2。我有一个规则,将所有请求发送到匹配规则的不同服务器。

The settings are a bit like this: http://blogs.iis.net/wonyoo/archive/2008/07/09/application-request-routing-arr-as-a-reverse-proxy.aspx

设置有一点类似:http://blogs.iis.net/wonyoo/archive/2008/07/09/09/09/09/09/09/application -request-routing-arr-as-a-reverse-proxy.aspx。

使用IIS应用程序请求路由(ARR)实现ASP。NET MVC

My rule is just a bit different it is /shop(.*). Only requests that contain shop are send to a different server. I have to use rewrite, not redirect (The same as in the Picture)

我的规则就是有点不同,它是/shop(. .*)。只有包含shop的请求才会发送到另一个服务器。我必须重写,而不是重定向(与图片相同)

This works as long as the original requests go to a non ASP.NET MVC web. I tried to use a plain htm file in the webfolder and it worked. If put a compiled ASP.NET application into the webfolder it worked. But as soon as I put an ASP.NET MVC web into the folder, request arr served by this application.

只要将原始请求发送到非ASP就可以。净MVC web。我尝试在webfolder下使用一个普通的htm文件,它就能工作。如果放一个编译好的ASP。NET应用程序到它工作的webfolder。但是只要我放一个ASP。NET MVC web到文件夹中,请求arr由这个应用程序服务。

My understanding is that the ARR should kick in before the web application gets the chance to handle the request. Did anybody use ARR sucessfully as a reverse proxy for a ASP.NET MVC web?

我的理解是,ARR应该在web应用程序获得处理请求的机会之前启动。有人成功地使用ARR作为ASP的反向代理吗?净MVC web吗?

EDIT

编辑

Here is the resulting web config when the rewrite roule is entered. With this rule I get a 404 that indicates that the rule is not used.

这是在输入重写roule时生成的web配置。有了这条规则,我得到一个404,它表示不使用该规则。

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>

  <appSettings />

  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>

    <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
    -->
    <compilation debug="false">
      <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>

    <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>

    <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->

    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </controls>

      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Linq" />
        <add namespace="System.Collections.Generic" />
      </namespaces>
    </pages>

    <httpHandlers>
      <remove verb="*" path="*.asmx" />
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
      <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="OptionInfer" value="true" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>
  <system.web.extensions />
  <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
  -->
  <system.webServer>
        <rewrite>
            <rules>
                <rule name="shop" stopProcessing="true">
                    <match url="^shop/([_0-9a-z-.]+)" />
                    <action type="Rewrite" url="article.aspx?title={R:1}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ScriptModule" />
      <remove name="UrlRoutingModule" />
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated" />
      <remove name="ScriptHandlerFactory" />
      <remove name="ScriptHandlerFactoryAppServices" />
      <remove name="ScriptResource" />
      <remove name="MvcHttpHandler" />
      <remove name="UrlRoutingHandler" />
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
  </system.webServer>
</configuration>

5 个解决方案

#1


14  

In the Global.asax.cs file add the following route entry:

asax。cs文件添加以下路径条目:

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

This solved by me the problem.

这就解决了我的问题。

It appears that the MVC routing system kicks in before ARR, which makes sense when running in integrated mode.

在ARR之前出现了MVC路由系统,这在集成模式下运行是有意义的。

#2


5  

We have almost the exact same setup you describe. We found that MVC and ARR won't plan nice in the same site. I suspect because the MVC routing and ARR routing do similar things and interfere. To work around it, we had to put just the ARR rules in a separate website. The domain and everything points to the ARR site, which will then send the requests where they need to go.

我们有几乎和你描述的一样的设置。我们发现MVC和ARR在同一个站点上不会有很好的计划。我怀疑,因为MVC路由和ARR路由会做类似的事情,并会产生干扰。为了解决这个问题,我们必须把ARR规则放在一个单独的网站上。域和所有内容都指向ARR站点,然后该站点将把请求发送到需要的地方。

We have specific rules that handle the specific cases, and a catch-all rule at the end that sends the rest of the requests to the MVC site.

我们有特定的规则来处理特定的情况,最后还有一个统一的规则,它将其余的请求发送到MVC站点。

#3


0  

It sounds like the HttpModules for ASP.Net MVC and ARR are registered in the wrong order.

它听起来像是ASP的httpmodule。Net MVC和ARR的注册顺序是错误的。

Can you show us your web.config?

你能给我们看看你的web.config吗?

#4


0  

Basically the problem is the ASP.NET MVC app isn't quite expecting /Shop to be part of the url and is acting accordingly. The best way to fix this would be to deploy the MVC app into an application living in the proxied site at /Shop. Then there will not need to be a translation to a sub URI and all the fun that can entail.

主要的问题是ASP。NET MVC应用程序并不期望/Shop成为url的一部分,而是相应地采取行动。解决这一问题的最好方法是将MVC应用程序部署到位于/商店的proxied站点中的应用程序中。然后就不需要对子URI进行翻译,也不需要所有的乐趣。

#5


0  

I've just found that if you place rewrite rules on the server level they will be saved to %systemroot%\system32\inetsrv\config\applicationHost.config inside system.webServer\rewrite\globalRuels and will work.

我刚刚发现,如果您在服务器级别上放置重写规则,它们将被保存到%systemroot%\system32\inetsrv\config\applicationHost中。系统内配置。网络服务器\重写\ globalRuels和将工作。

But I am still wondering why it does not work with rules in Web.config.

但是我仍然想知道为什么它不能在Web.config中使用规则。

#1


14  

In the Global.asax.cs file add the following route entry:

asax。cs文件添加以下路径条目:

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

This solved by me the problem.

这就解决了我的问题。

It appears that the MVC routing system kicks in before ARR, which makes sense when running in integrated mode.

在ARR之前出现了MVC路由系统,这在集成模式下运行是有意义的。

#2


5  

We have almost the exact same setup you describe. We found that MVC and ARR won't plan nice in the same site. I suspect because the MVC routing and ARR routing do similar things and interfere. To work around it, we had to put just the ARR rules in a separate website. The domain and everything points to the ARR site, which will then send the requests where they need to go.

我们有几乎和你描述的一样的设置。我们发现MVC和ARR在同一个站点上不会有很好的计划。我怀疑,因为MVC路由和ARR路由会做类似的事情,并会产生干扰。为了解决这个问题,我们必须把ARR规则放在一个单独的网站上。域和所有内容都指向ARR站点,然后该站点将把请求发送到需要的地方。

We have specific rules that handle the specific cases, and a catch-all rule at the end that sends the rest of the requests to the MVC site.

我们有特定的规则来处理特定的情况,最后还有一个统一的规则,它将其余的请求发送到MVC站点。

#3


0  

It sounds like the HttpModules for ASP.Net MVC and ARR are registered in the wrong order.

它听起来像是ASP的httpmodule。Net MVC和ARR的注册顺序是错误的。

Can you show us your web.config?

你能给我们看看你的web.config吗?

#4


0  

Basically the problem is the ASP.NET MVC app isn't quite expecting /Shop to be part of the url and is acting accordingly. The best way to fix this would be to deploy the MVC app into an application living in the proxied site at /Shop. Then there will not need to be a translation to a sub URI and all the fun that can entail.

主要的问题是ASP。NET MVC应用程序并不期望/Shop成为url的一部分,而是相应地采取行动。解决这一问题的最好方法是将MVC应用程序部署到位于/商店的proxied站点中的应用程序中。然后就不需要对子URI进行翻译,也不需要所有的乐趣。

#5


0  

I've just found that if you place rewrite rules on the server level they will be saved to %systemroot%\system32\inetsrv\config\applicationHost.config inside system.webServer\rewrite\globalRuels and will work.

我刚刚发现,如果您在服务器级别上放置重写规则,它们将被保存到%systemroot%\system32\inetsrv\config\applicationHost中。系统内配置。网络服务器\重写\ globalRuels和将工作。

But I am still wondering why it does not work with rules in Web.config.

但是我仍然想知道为什么它不能在Web.config中使用规则。