to read Web.Config Section

F

fabrice

Hello,

Is that a way for reading section of the web.config by code ?
I m able to read the section <appSettings> like this :


<appSettings>
<add key="AppVer" value="Version 0.8 beta"/>
</appSettings>


Dim test As System.Collections.Specialized.NameValueCollection
test = CType
(System.Configuration.ConfigurationSettings.GetConfig("appSettings"),
System.Collections.Specialized.NameValueCollection)
dim mytest as string = CType (test("AppVer"), String )
response.write(mytest)

And it's OK

But i can't with the section globalization

<system.web>

<globalization requestEncoding="iso-8859-1"
responseEncoding="iso-8859-1"
culture="fr-FR" uiCulture="fr-FR" />


Dim testAs System.Collections.Specialized.NameValueCollection

test= CType
(System.Configuration.ConfigurationSettings.GetConfig("system.web/globalization"),
System.Collections.Specialized.NameValueCollection)
dim mytest as string = CType (test("culture"), String )
'response.write(mytest)

it does not work.

How can i get information in globalization section ?

thanks
fabrice
 
K

Karl Seguin

You won't be able to use System.Config to help you, but you can load it like
a normal XML file and use xpaths or some other method.

Karl
 
J

Juan T. Llibre

In ASP.NET 2.0, it's fairly easy :

Dim configPath As String = "/yourVirtualApplicationPath"
Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(configPath)
Dim configSection As System.Web.Configuration.GlobalizationSection = CType(config.GetSection("system.web/globalization"), _
System.Web.Configuration.GlobalizationSection)
lblMessage.Text = "The web.config's file path is : " & config.FilePath
lblMessage2.Text = "The configuration section's name is : " & configSection.SectionInformation.Name
lblMessage3.Text = "The configured culture is : " & configSection.Culture
lblMessage4.Text = "The configured uiCulture is : " & configSection.uiCulture
lblMessage5.Text = "The configured requestEncoding is : " & configSection.RequestEncoding.ToString()
lblMessage6.Text = "The configured responseEncoding is : " & configSection.ResponseEncoding.ToString()
lblMessage7.Text = "The configured fileEncoding is : " & configSection.FileEncoding.ToString()
etc...
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top