ASP.NET站点在IIS中使用ARR(应用程序请求路由(实现负载平衡。相应的URL重写规则位于applicationHost.config.中
有没有办法在一个新的配置文件中分离这个规则?不再支持标记configSource
。我读过关于childSource
标签的文章,但它只在部分中得到支持。
以下是applicationHost.config:中的规则
<system.webServer>
<rewrite>
<globalRules>
<rule name="ARR_TestFarm_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="http://TestFarm/{R:0}" />
</rule>
</globalRules>
</rewrite>
</system.webServer>
我敢打赌,在这种情况下,您希望在测试/本地开发和生产/部署场景之间有不同的配置设置。
我通常使用配置转换来实现这一点,而且效果很好。大致如下:
您的app.config
文件基本上就是一个模板。对于给定的示例,您的示例可能如下所示:
...
<system.webServer>
<rewrite>
<globalRules>
<rule>
</rule>
</globalRules>
</rewrite>
</system.webServer>
...
然后,创建另一个文件,称之为app.local.config
,它看起来像这样:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<rewrite>
<globalRules>
<rule xdt:Transform="Replace">
<!-- local rule -->
</rule>
</globalRules>
</rewrite>
</system.webServer>
</configuration>
...
和另一个名为app.release.config
的文件
...
<system.webServer>
<rewrite>
<globalRules>
<rule xdt:Transform="Replace" name="ARR_TestFarm_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="http://TestFarm/{R:0}" />
</rule>
</globalRules>
</rewrite>
</system.webServer>
...
你可以在这里找到转换的文档:https://learn.microsoft.com/en-us/previous-versions/dd465326(v=vs.100(
VS在转换文件时内置了一些规则,但IIRC仅适用于web.config。FastKoala的添加将允许app.config转换以及在构建时对其进行转换的能力,https://marketplace.visualstudio.com/items?itemName=JonDaviswijitscom.FastKoala-WebAppconfigXML转换