2 Replies - 1521 Views - Last Post: 16 December 2009 - 09:02 AM Rate Topic: -----

#1 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

read web.config

Post icon  Posted 16 December 2009 - 07:15 AM

HI, I have one asp.net aplication, and I want to read information since the web.config becouse I have two values with keys, and I need the values. I have the next code:

Dim url, ruta1_general As String
		Dim rootWebConfig1 As System.Configuration.Configuration
		rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Nothing)
		If (0 < rootWebConfig1.AppSettings.Settings.Count) Then
			Dim customSetting As System.Configuration.KeyValueConfigurationElement
			customSetting = rootWebConfig1.AppSettings.Settings("pablo")
			If Not (Nothing = customSetting.Value) Then
				url = customSetting.Value()
			End If
			customSetting = rootWebConfig1.AppSettings.Settings("rutageneral")
			If Not (Nothing = customSetting.Value) Then
				ruta1_general = customSetting.Value()
			End If
		End If


Here is the web.config:

<?xml version="1.0"?>

<configuration>

  
  <appSettings>
	<add key="pablo" value="value1" />
	<add key="rutageneral" value="value2" />
  </appSettings>
  
  <connectionStrings/>
  
	<system.web>
.
.
.


THe problem is the next, when I start the program, the application doesn't enter in the first IF of my code:

If (0 < rootWebConfig1.AppSettings.Settings.Count) Then

I don't Know what is happening, is somebody has an idea would be great! Thank you! :)

Pablo

Is This A Good Question/Topic? 0
  • +

Replies To: read web.config

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: read web.config

Posted 16 December 2009 - 08:13 AM

You need to provide the root path to where the web.config is located, currently you have it set to Nothing.

rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Nothing)


Lets say that your web application is called "MyWebApp", then you would access the web.config like so:
rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebApp")

Was This Post Helpful? 1
  • +
  • -

#3 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

Re: read web.config

Posted 16 December 2009 - 09:02 AM

Thank you! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1