Home arrow GIS Data & Resources arrow Scripts and Code arrow C# Code arrow ASP.NET & Ampersand in AppSetting or ConnectionString
ASP.NET & Ampersand in AppSetting or ConnectionString PDF Print E-mail

Written by Steve Gourley,

XML rules make is so that the & character is the token for beginning of a reference. With ASP.NET, you have the ability to store application specific settings (AppSettings) and connectionStrings to name a few. Persay you wanted to store a url with a query string in it eg: 

<appSettings>
        <add key="myLink" value="http://mapserv.utah.gov/SGID?map=true&county=salt lake"/>
</appSettings>

Your .NET application would throw and error and say you needed a semi colon. Another example would be storing the connection string to a sql database.

<connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=mySqlDatabase;Initial Catalog=Table;User ID=ADMIN;Password=&password&" providerName="System.Data.SqlClient"/>
</connectionStrings>

 This would not compile.

The solution to the problem is relatively simple but if you didn't know better it may be a bit of a stumper. All you need to do is convert your & to &amp;  The above samples would be 

<appSettings>
        <add key="myLink" value="http://mapserv.utah.gov/SGID?map=true&amp;county=salt lake"/>
</appSettings> 

<connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=mySqlDatabase;Initial Catalog=Table;User ID=ADMIN;Password=&amp;password&amp;" providerName="System.Data.SqlClient"/>
</connectionStrings>

 

And your off!


Users' Comments  
 

No comment posted

Add your comment

30, Jun. 2008
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for