adding custom setting into web.config, how??

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

ASP.NET 2.0

I'm wondering how to add a custom setting into web.config. From this website
I'm doing a http request to another website, and I would like to have the
webaddress of this other website stored as a value in web.config. So just in
case the webaddress is wrong I wouldn't need to recompile it later... So
where in web.config should such a custom setting be placed?

Lets say the custom section is like this:
<test>www.test.com/index.asp<test>

How can I access this <test> value using configurationmanager?? or is it
correct to use configurationmanager to access the value??

Jeff
 
You can use the appSettings section :

<appSettings>
<add key="link1" value="http://www.test.com/index.asp"/>
</appSettings>

To get the setting :

<script language="vb" runat="server">
Sub Page_Load()
Dim mylink1 as String = (ConfigurationSettings.AppSettings("link1"))
' do something with the link1 string variable, which now holds the link you want.
End Sub
</script>

If you want to use the ConfigurationManager, use :

Dim mylink1 as String = ConfigurationManager.AppSettings.Get("link1")

Either one will do...




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
To get the setting :

<script language="vb" runat="server">
Sub Page_Load()
Dim mylink1 as String = (ConfigurationSettings.AppSettings("link1"))
' do something with the link1 string variable, which now holds the link you want.
End Sub
</script>

This method is documented as being obsolete in ASP.NET v 2

Is it a good idea to perpetuate it for new projects?
 
Jeff,
does this work for you?

use appSettings in web.config like:

<appSettings>
<add key="urlTest" value="www.test.com/index.asp" />
</appSettings>

then you can read this value by doing:
Dim urlTest As String =
System.Web.Configuration.WebConfigurationManager.AppSettings("urlTest")

you can add Imports System.Web.Configuration.WebConfigurationManager to your
souce file and use just
Dim urlTest As String = AppSettings("urlTest")

Bruno
 
Back
Top