Read Variable from Web.Config

Amira Elsayed Ismail picture Amira Elsayed Ismail · Oct 4, 2010 · Viewed 138.2k times · Source

How can I add and read the value from web.config file?

Answer

PrateekSaluja picture PrateekSaluja · Oct 4, 2010

Given the following web.config:

<appSettings>
     <add key="ClientId" value="127605460617602"/>
     <add key="RedirectUrl" value="http://localhost:49548/Redirect.aspx"/>
</appSettings>

Example usage:

using System.Configuration;

string clientId = ConfigurationManager.AppSettings["ClientId"];
string redirectUrl = ConfigurationManager.AppSettings["RedirectUrl"];