Please Help!!! Cannot read from the web.config file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a specific way that System.Configuration.AppSettings.GetValue("key")
works?

This method reads the value from the Web.config file, only if I read from a
UI component(Web Server(.aspx files) or a user control or a DLL that runs in
the Web Server).

If I read the Web.config file from a ClassLibrary the
System.Configuration.AppSettings.GetValue("key") return null.

Any ideas?

Raj
 
You're doing something wrong, because you should be able to read values from
the web.config or app.config file from anywhere.

<appSetting>
<add key="FavoriteAnimal" value="Bear"/>
</appSetting>

this should be nested inside the <configuration> section (notice
configuration is singular)

...


if(null!=System.Configuration.ConfigurationSettings.AppSettings["FavoriteAni
mal"])
{
string x =
System.Configuration.ConfigurationSettings.AppSettings["FavoriteAnimal"];
}
 
Back
Top