c# - Problems retrieving appsettings added during application start -


I am having a strange problem, where in my application_start () my global.asax, I have something that my All of my app settings are received from a name / pricing table closed for the database, and then they are Application.Add (name, value) .

Another project has an 'application mask' which is used on my service layers, data layers and so on so that I can do various bits and pieces to get the settings.

In my database, I have some of the entries:

  configuration | ConfigValue WebServiceUsername | MyUsername WebServicePassword | MyPassword  

In my method, I go and get these values ​​from the database, and put them in my application:

  Secure Zero GetApplicationSettings () {// Obtain all configured values ​​from the database, and then enter them in the application keys ... var appConfigAttributes = ApplicationConfigurationService.GetAppConfigNames (); Foreach (Configure various apps in app configurations) {apps.add (ap conif config.php, config.config value); }}  

In this way, I call the value later from the application:

  public static string WebServiceUsername {get {return WebConfigurationManager.AppSettings [" WebServiceUsername "]; }}  

This is where things are weird.

If I call the application mask from my web layer:

  & lt;% = ApplicationFacade.WebServiceUsername% & gt;  

I can not find anything (yes, I've tried just the configuration manager in the law!).

But this is strange ...

If I manually mine my web I enter an application key in the config file ...

  & lt; App settings and gt; & Lt; Add key = "putz" value = "mash" /> & Lt; / AppSettings & gt;  

And then in the form of puts, my applications create similar assets in the famed class, when I call ( & lt;% = ApplicationFacade.Putz% & gt; ) I was returned ' mash .

So, I know that my application is working correctly. So is this my code in application_start ()?

Well, if I put it in my view & lt;% = application ["WebServiceUsername"]% & gt; , Username has been refunded.

What gives ?!

Answer

  ConfigurationManager.AppSettings.Set (appConfig.ConfigName, appConfig.ConfigValue);    

in Application_Start when you use the application Object is an example that is used to keep application specific settings in memory and there is nothing to do with the key / value app setting stored in the web / config.

  • When you use WebConfigurationManager.AppSettings ["SomeKey"] it will be related to someKey related to app settings Section of web.config will return the section.
  • When you use the application [[someKey]] , this application will return the cached values ​​in the frequency.

Both are completely unrelated and you can type "WebConfigurationManager.AppSettings [" SomeKey "] in the application [" something ""

do not expect to read the stored values.

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -