首页 > 解决方案 > c# winform app.config "&" char 在字符串中不起作用

问题描述

在我的 app.config 文件中,我想添加 param2="&password=" 但它不起作用,因为 "&" char 知道为什么吗?

 <configSections>
        <sectionGroup name="API">
          <section name="loginURL" type="System.Configuration.SingleTagSectionHandler"/>
        </sectionGroup>
 </configSections>
 <API>
        <loginURL url="http://test.fr:81/api/sm?" param1="name=" param2="&password="/>
 </API>

标签: c#app-config

解决方案


由于web.config文件是 XML,它们遵循正常的 XML 规则。这意味着属性是 XML 编码的。要使用&标志,您应该将其替换为&amp;

 <configSections>
        <sectionGroup name="API">
          <section name="loginURL" type="System.Configuration.SingleTagSectionHandler"/>
        </sectionGroup>
 </configSections>
 <API>
        <loginURL url="http://test.fr:81/api/sm?" param1="name=" param2="&amp;password="/>
 </API>

推荐阅读