1

我使用 IIS Url Rewrite 模块,该模块在system.webServer/rewrite.

我正在尝试使用基本的Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilderconfigBuilder,mode="Expand"以便可以将环境变量注入到我的<rewrite>配置部分,如下所示:

<configuration>
    <configSections>
        ...
        <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
        ...
    </configSections>
    ...
    <configBuilders>
        <builders>
            <add name="MyConfigBuilder" mode="Expand" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=1.0.0.0, Culture=neutral" />
        </builders>
    </configBuilders>
    ...
    <system.webServer>
        <rewrite configBuilders="MyConfigBuilder">
            <providers>
                <provider name="SomeProvider">
                    <settings>
                        <add key="someKey" value="${someEnvToken}" />
                    </settings>
                </provider>
            </providers>
            ...
        </rewrite>
    </sytem.webServer>
</configuration>

我得到一个500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.没有堆栈跟踪或任何进一步信息的。Visual Studio 智能感知状态The "configBuilders" attribute is not allowed,我猜这解释了 500 错误。

如果我尝试在重写配置中的任何其他级别,例如在子元素上,或者<providers>然后我得到一个 500 错误 <provider><settings>Unrecognized attribute 'configBuilders'

我也尝试将configBuilders属性放在<system.webServer>元素本身上,但仍然存在错误。

据我所知,该属性只configBuilders需要继续configSection。这意味着system.webServer因为它是一个configSectionGroup. 理论上,rewrite应该是一个configSection因此接受的属性,不是吗?

如何让它与 url rewrite 模块一起使用?如果它不能工作,那么我必须问:如果它所能做的只是appSettings和,那有什么意义connectionStrings呢?我知道您可以为自己的自定义部分创建自定义部分处理程序。问题是这不是一个自定义部分——它是微软制作的一个高度使用的模块,几乎所有在 IIS 上运行网站的人都在使用它!

- - 编辑 - -

从那以后,我发现该<rewrite>元素也是 aconfigSectionGroup但所有子元素都是configSection,所以它应该在理论上起作用。我找到了这个链接:

https://githubmemory.com/repo/aspnet/MicrosoftConfigurationBuilders/issues/149

一个人正在为一个似乎sectionHandler有效的知名部分创建自己的部分。<customErrors>我相信它会指示 configBuilders 处理该部分,否则它会忽略它。

该类声明如下:

public class CustomErrorsSectionHandler : Microsoft.Configuration.ConfigurationBuilders.SectionHandler<CustomErrorsSection>

注意CustomErrorsSectionis inSystem.Web.Configuration和 is public sealed

我试图通过创建一个来复制它,sectionHandler<Microsoft.Web.Management.Iis.Rewrite.ProvidersSection>但它是internal sealed不可能实现的。

这真的不可能吗??

4

0 回答 0