iis - applicationHost.config 中是否有替代 configSource 的方法?

标签 iis url-rewriting applicationhost configsource

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.configs。 FastKoala 的添加将允许 app.config 转换以及在构建时转换它们的能力,https://marketplace.visualstudio.com/items?itemName=JonDaviswijitscom.FastKoala-WebAppconfigXMLtransforms

关于iis - applicationHost.config 中是否有替代 configSource 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53401234/

相关文章:

apache - 配置 htaccess 进行 url 重写

iis - httpCompression 在 web.config 中不起作用

asp.net - 即使在 applicationHost.config 中允许,gzip 压缩也不起作用

asp.net - 覆盖 ASP.NET 子应用程序中的 web.config

java - 无法从asp页面调用java方法:

.htaccess 和过滤 $_GET

iis - Applicationhost.config 未显示更改

c# - 为什么 HttpContext.Current 为空?

iis - 如何手动启动 IIS Express

.htaccess - 当 '/folder/index.html' 被剥离时,如何删除 'index.html' 的尾部斜杠?