Dennis
Dennis

Reputation: 21

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"];

But this doesn't work either.

What am I doing wrong?

Upvotes: 1

Views: 7116

Answers (2)

Kev
Kev

Reputation: 119806

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 usings 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.

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

System.Configuration.ConfigurationManager.Appsettings.Get("imglServer");

Try that.

Upvotes: 6

Related Questions