By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

reading web.config in Visual Studio 2005

P: n/a
The code below is directly from Microsoft's help. It describes how to
read a value from the Web.config file. I tried out this code and it
does not appear to work (at least when I try it).

If my web.config file I have the following:
<add key="WebServer" value="localhost"/>

I want to read out the WebServer value and I used Microsoft's code
below. But again, it doesn't work. However, just doing
AppSettings.Item("WebServer") did the trick. I have no idea why
Microsoft's code below doesn't work. Anybody want to try and explain?

Dim rootWebConfig1 As System.Configuration.Configuration
rootWebConfig1 =
System.Web.Configuration.WebConfigurationManager.O penWebConfiguration(Nothing)
If (0 < rootWebConfig1.AppSettings.Settings.Count) Then
Dim customSetting As
customSetting =
rootWebConfig1.AppSettings.Settings("customsetting 1")
If Not (Nothing = customSetting.Value) Then
Console.WriteLine("customsetting1 application string = {0}",
Console.WriteLine("No customsetting1 application string")
End If
End If

Oct 19 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.