.net 转义 & 在 App.config

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10883745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:27:29  来源:igfitidea点击:

Escape & in App.config

.netapp-config

提问by developer747

I have the following piece of config in my App.config file:

我的 App.config 文件中有以下配置:

<add key="ConnectionString" 
     value="INITIAL CATALOG=myDatabase;DATA SOURCE=myServer;User ID=myUser;Password=!&myPass99;"/>

The above connection string is rejected by Visual Studio intellisense. It says entity myPass99not defined. The problem is caused by the & in the password.

上述连接字符串被 Visual Studio 智能感知拒绝。它说实体myPass99未定义。问题是由密码中的 & 引起的。

How do I escape it?

我该如何逃脱?

回答by jglouie

Escape the ampersand by using &amp;in place of the &

使用&amp;代替符号来转义符号&

As an FYI, see here for further characters: What characters do I need to escape in XML documents?

仅供参考,请参阅此处了解更多字符: 我需要在 XML 文档中转义哪些字符?