Can't read <appSetting> value from my ASP.NET web.config file
I want to retrieve a value from my <appSettings>
section in my web.config
file. The key is named imgServer
.
I tried this but it doesn't work:
Label1.Text = System.Configuration.ConfigurationSettings.AppSettings.Get("imglServer");
I then tried:
Label1.Text = ConfigurationSettings.AppSettings["imgServer"];
开发者_Go百科But this doesn't work either.
What am I doing wrong?
System.Configuration.ConfigurationManager.Appsettings.Get("imglServer");
Try that.
You don't specify what version of ASP.NET you're using or which language:
In C# it would be:
Label1.Text = ConfigurationManager.AppSettings["imgServer"];
You might also have to add a using System.Configuration;
in the using
s section of your class file or code-behind.
In VB.NET it'd be:
Label1.Text = ConfigurationManager.AppSettings("imgServer")
' Note the round brackets instead of the square brackets as used by C# ^^^
You might also have to add a reference to System.Configuration
if it's not already there.
精彩评论