The writing method for special symbols in the config file in C #.

Source: Internet
Author: User
Tags connectionstrings

App. Config:

1 <?xml version= "1.0" encoding= "Utf-8"? >2 <configuration>3     <startup> 4         < Supportedruntime version= "v4.0" sku= ". netframework,version=v4.5 "/>5     </startup>6   <connectionstrings>7     <add name=" Dbconnstring "connectionstring=" Data source=.;i Nitial catalog=mytest123456; User Id=sa; password=123&456 "/>8   </connectionstrings>9 </configuration>

Because the password for the database connection contains the special character "&", the following error message appears at compile time:

Obviously the compiler does not know "&456", how to solve it, always can not change the password it?

In fact, App. Config is an XML file with special characters to be HTML escaped in an XML file.

<,>,& in HTML has special meanings (<,>, used for link-sign,& for escaping) and cannot be used directly. These symbols are not displayed in the pages we end up seeing, and if we want to display them in a Web page, we'll use the HTML escape string (Escape Sequence).

HTML Special escape Character list

Most commonly used character entities

Show Description Entity name Entity number

Spaces &nbsp; & #160;

< less than &lt; & #60;

> Greater than &gt; & #62;

& & Symbols &amp; & #38;

"Double quotes &quot; & #34;

© Copyright &copy; & #169;

® Registered Trademarks &reg; & #174;

™ Trademark (United States) ™& #8482;

X Multiplication Sign &times; & #215;

÷ Division sign &divide; & #247;

So just escape the "&" and change the password to

password=123&amp;456 "

Succeeded by compiling.

The writing method for special symbols in the config file in C #.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.