Hello All,
How can I add and read value from web.config
Thanks in Advance
Hello All,
How can I add and read value from web.config
Thanks in Advance
Assuming the key is contained inside the <appSettings>
node:
ConfigurationSettings.AppSettings["theKey"];
As for "writing" - put simply, dont.
The web.config is not designed for that, if you're going to be changing a value constantly, put it in a static helper class.
I would suggest you to don't modify web.config from your, because every time when change, it will restart your application.
However you can read web.config using System.Configuration.ConfigurationManager.AppSettings
Ryan Farley has a great post about this in his blog, including all the reasons why not to write back into web.config files: Writing to Your .NET Application's Config File
Hello ,
Suppose In web config You have variable like that
<appSettings>
<add key="ClientId" value="127605460617602"/>
<add key ="RedirectUrl" value="http://localhost:49548/Redirect.aspx"/>
</appSettings>
In aspx page you can use like that ..........
1st you have to add namespace
using System.Configuration;
Then you can use
string Clientid=ConfigurationManager.AppSettings["ClientId"].ToString();
string Redircturl=ConfigurationManager.AppSettings["RedirectUrl"].ToString();
Hope it works for you.