Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem retrieving appSettings from Web.Config

Status
Not open for further replies.

KenniM

Programmer
Nov 27, 2002
25
DK
Hi everyone!

As the subject says I have problems retrieving appSettings from my web.config file.

The web.config file is placed at the root as it should be and I have the following name/values added:

<appSettings>
<add key=&quot;da-DK&quot; value=&quot;100&quot;/>
<add key=&quot;de-DE&quot; value=&quot;742,87&quot;/>
<add key=&quot;en-US&quot; value=&quot;630,19&quot;/>
</appSettings>

In my main aspx file i try to retrieve these values as follows, but I get absolutely nothing back. Why?

string strValutaValue = ConfigurationSettings.AppSettings[&quot;da-DK&quot;];

There are square braces arround the &quot;da-DK&quot; - don't knwo why it isn't there now.

It shold return &quot;100&quot; here right?.

However it seems as if it dosn't matter what I write in the []. I could write [&quot;Whatever&quot;] and it dosn't even through me an error.

What am I doing wrong here, anyone! :D

best regards
kenni







 
I know that if you are using VB, it should be (), not []

so...

<add key=&quot;da-DK&quot; value=&quot;100&quot;/>
(no braces in here at all)

then

ConfigurationSettings.Appsettings(&quot;da-DK&quot;)

If you aren't using VB, I don't know what might be wrong
 
Thank you jen89.

You are right, when programming in C# you use []. I already know this, but thank you anyway! Certanly something one could easely over look.

However, I'm still stuck with my problem. It's like there's no connection between my aspx file and the web.config. And everywhere i read about this it just looks so easy. Bla., bla. ... just write ConfigurationSettings.AppSettings[key] and everything will be fine.

It's wierd I tell you.....Wieeeerrrd!
Ok I know, that was a little bit strange, huh! :D

Thanks
Kenni
 
Solved the problem! I don't know why I didn't see this from the start! :D

<!--
<appSettings>
<add key=&quot;da-DK&quot; value=&quot;100&quot;/>
<add key=&quot;de-DE&quot; value=&quot;742,87&quot;/>
<add key=&quot;en-US&quot; value=&quot;630,19&quot;/>
</appSettings>
-->

Yep, I see them too! I didn't realize that the <appSettings> section was commented out by the <!-- -->.

best regards
Kenni



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top