加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 自定义部分的Web配置转换

发布时间:2020-12-16 04:16:03 所属栏目:asp.Net 来源:网络整理
导读:我的MVC 5应用程序中有许多不同的Web.config用于不同的环境 – 例如测试/生产 我有适当的网络转换来更改不同环境的值.例如,我的web.config文件中有以下应用程序设置: appSettingsadd key="DevDisplayPanel" value="true" //appSettings 然后在我的Web.Test.
我的MVC 5应用程序中有许多不同的Web.config用于不同的环境 – 例如测试/生产

我有适当的网络转换来更改不同环境的值.例如,我的web.config文件中有以下应用程序设置:

<appSettings>
<add key="DevDisplayPanel" value="true" />
</appSettings>

然后在我的Web.Test.config和Web.Prod.config中使用Web转换来更改值,如下所示:

<appSettings>
<add key="DevDisplayPanel" 
     xdt:Transform="Replace" 
     xdt:Locator="Match(key)" 
     value="false" />
<appSettings>

但是在我的Web.config中,我也有自己的自定义部分,它位于< appSettings>之外.部分如下:

<myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://dev-myurl1.com"/>
      <add zone="Zone2" url="https://dev-myurl2.com"/>
      <add zone="Zone2" url="https://dev-myurl3.com"/>
    </serverList>
  </myCustomSection>

我的问题是 – 是否可以进行Web转换,以便Test和Prod看起来如下所示:

测试:

<myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://test-myurl1.com"/>
      <add zone="Zone2" url="https://test-myurl2.com"/>
      <add zone="Zone2" url="https://test-myurl3.com"/>
    </serverList>
  </myCustomSection>

PROD:

<myCustomSection>
    <serverList>
      <add zone="Zone1" url="https://prod-myurl1.com"/>
      <add zone="Zone2" url="https://prod-myurl2.com"/>
      <add zone="Zone2" url="https://prod-myurl3.com"/>
    </serverList>
  </myCustomSection>

解决方法

您可以尝试替换< serverList>的内容.标签.

测试:

<myCustomSection>
    <serverList xdt:Transform="Replace">
        <add zone="Zone1" url="https://test-myurl1.com"/>
        <add zone="Zone2" url="https://test-myurl2.com"/>
        <add zone="Zone2" url="https://test-myurl3.com"/>
    </serverList>
</myCustomSection>

PROD:

<myCustomSection>
    <serverList xdt:Transform="Replace">
        <add zone="Zone1" url="https://prod-myurl1.com"/>
        <add zone="Zone2" url="https://prod-myurl2.com"/>
        <add zone="Zone2" url="https://prod-myurl3.com"/>
    </serverList>
</myCustomSection>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读