adding custom setting into web.config, how??

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
 
J

Juan T. Llibre

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

Phil H

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?
 
B

Bruno Piovan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top