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;
}
}
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;
}
}