在 web.config 转换中阻止“>”符号转换为“>”

Stop ">" symbol from being converted to ">" in web.config transform

当我 运行 我的 Web.config 转换时,它将 > 符号转换为 > 。有没有办法逃避这种转换?

输入:

<add key="MyPassword" value=">" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>

不需要的输出:

<add key="MyPassword" value="&gt;" />

期望的输出:

<add key="MyPassword" value=">" />

不幸的是,这似乎是预期的行为。在这个相关问题中,您可以看到用户向 Microsoft 提交了一个错误,他们已将其关闭为 "By Design"。

Web Config Transforms are HTML Encoding some of the config and breaking it

XML 的性质阻止了这一点。

为了不让您挂在这里,我们提供了一些建议。

  1. google Web.config、

  2. 中的 CDATA
  3. 您可能希望创建一种方法,1. 读取设置和 2. 解码值。

  4. 话虽这么说,XML 读写的性质,这个值应该以未编码的方式返回。我看到您正在使用 MVC。就像指针一样,也许这是按预期工作的,您只需要 @Html.Raw() 在您的视图中输出?只是猜测。

祝你好运。