I have a key in the web.config file like:
<add key="MailFrom" value="[email protected]"/>
I need to access it in the code behind.How to do this in c#?
I have a key in the web.config file like:
<add key="MailFrom" value="[email protected]"/>
I need to access it in the code behind.How to do this in c#?
You could use the AppSettings property indexer:
string from = ConfigurationManager.AppSettings["MailFrom"];
System.Configuration.dll by default, which is required to access System.Configuration.ConfigurationManager, even though parts of the System.Configuration namespace are available without it. Worth mentioning for anyone that comes across this question but for a non-WebForms project (as WebForms seems to reference it for you).