c# - 如何使用 Web.config 转换更改 appSettings 部分中的属性值

标签 c# asp.net .net web-config

是否可以转换以下 Web.config appSettings 文件:

<appSettings>
    <add key="developmentModeUserId" value="00297022" />
    <add key="developmentMode" value="true" />
    /* other settings here that should stay */
</appSettings>

像这样:

<appSettings>
    <add key="developmentMode" value="false" />
    /* other settings here that should stay */
</appSettings>

因此,我需要删除键 developmentModeUserId,并且我需要替换键 developmentMode 的值。

最佳答案

你想要这样的东西:

<appSettings>
  <add key="developmentModeUserId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
  <add key="developmentMode" value="false" xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"/>
</appSettings>

另请参阅:Web.config Transformation Syntax for Web Application Project Deployment

关于c# - 如何使用 Web.config 转换更改 appSettings 部分中的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11033001/

相关文章:

c# - protobuf-net - 从 .proto 生成的类 - 重复字段是否应该是只读的,没有 setter ?

c# - 查询 azure 表中的多个实体

c# - 最小起订量 - 模拟 MVC Controller 的 Response.Cookies.Clear()

javascript - 我可以将 JavaScript 变量传递给内联 ASP.NET 代码吗?

c# - 在 OpenTK 中获取鼠标窗口坐标 (C#~.NET)

C#数据分配问题

c# - 为什么我的代码显然在调用 LocalDataStoreMgr.GetNamedDataSlot?

asp.net - 重定向不适用于移动 View asp.net

c# ProcessStartInfo.Start - 读取输出但超时

c# - 在我的表单中显示另一个应用程序