I may put the website on a different server and it has links linking it especially as it is on sharepoint so there are addresses and ports, so i thought it's better to save the link in Web.Config file in order not to need to change it a lot. So where is the best place or tag to put it in, like for example connection strings is at: configuration->connectionstrings.
I have sometimes used appSettings
to store link templates
<configuration>
<appSettings>
<add key="link.template1" value="http://example.com:1234/" />
</appSettings>
</configuration>
Note that the url needs to be xml encoded, so if it includes querystring parameters you will need to encode the &
characters to &
(and possibly encode other characters as well):
<configuration>
<appSettings>
<add key="link.template1" value="http://example.com/p1=value&amp;p2=othervalue" />
</appSettings>
</configuration>
...and of course I should have hinted on how to use the values. Thanks @Tchami for providing that answer in the comments; added here for answer completeness:
string urlTemplate = ConfigurationManager.AppSettings["link.template1"];
If you don't already have it, you will need to add a reference to System.Configuration
to your project, and also a using System.Configuration
statement in the beginning of the code file.
I think you best bet here is to use a properties class that stores changes in the web.config. It's basically the same thing as using but it allows you to use either a default value set when you initially created the setting, or you can override it and use a value specified from the web.config file. If you're using VS2005 or VS2008, this is the way to go. Here's Microsoft's usage page on it: MSDN: Using Settings in C#