How can I refer to appSetting in another part of web.config

I have my appSettings defined in a separate configuration file called Appsettings.Dev.Config and I include this file inside my web.config , for example,

 <appSettings configSource="ConfigFiles\AppSettings.Dev.config"/> 

Let's say that one of the parameters in the file

 <add key="MailerEmailAccount" value=" myemail@myserver.com " /> 

Can I access the value of the MailerEmailAccount parameter elsewhere in web.config? How?

+7
source share
2 answers

No, the network configuration file cannot pull the โ€œsettingsโ€ from itself; it is not dynamic. The only dynamic functionality is the ability to enable another .config, but it's just "suck all these settings as if they were part of me."

+4
source

Perhaps you will create a custom ConfigurationSection that will pull the value from appSettings .

Here is an article that explains how to create a custom configuration section:
http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx

I don't know, this is what you are looking for, but this is the only way I can read the web.config parameter from web.config .

EDIT

I have not tested this, but maybe something like this will work ?:

 [ConfigurationProperty("localName", IsRequired = true, IsKey = true)] public string LocalName { get { return this["localName"] as string; } set { this["localName"] = WebConfigurationManager.AppSettings.Get(value); } } 
+4
source

All Articles