Accessing web.config programatically

R

Roger Helliwell

Hey all,

Our web app (.NET 2.0 beta 1) uses the web.config to store site-wide
settings. Most of these settings are in the <appSettings> section and
getting at them at runtime is a snap by using
ConfigurationSettings.AppSettings["ImageFolder"] for example

However, there are some ASP.NET settings that have their own sections
in the web.config that I want to get at as well. I've played around
with the GetConfig() method (code below) but so far no luck. I'm
trying to access the <globalization> section in order to determine the
Culture setting, but keep running into an Illegal cast exception.

How is this done?

Thanks,
Roger

.... snippet from web.config ...

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<globalization culture="en-CA" uiCulture="en-CA" />
<compilation debug="true" defaultLanguage="c#" />
</system.web>
</configuration>

---------------------------

// Returns the default culture that is used throughout the site
public static string Culture
{
get
{
object o =
ConfigurationSettings.GetConfig("system.web/globalization");
// Next line throws an Illegal cast exception
GlobalizationSection section = (GlobalizationSection) o;
return section.Culture;
}
}
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top