473,785 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing web.config programatically

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
ConfigurationSe ttings.AppSetti ngs["ImageFolde r"] 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 <globalizatio n> 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 ...

<configuratio n
xmlns="http://schemas.microso ft.com/.NetConfigurati on/v2.0">
<system.web>
<globalizatio n 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 =
ConfigurationSe ttings.GetConfi g("system.web/globalization") ;
// Next line throws an Illegal cast exception
GlobalizationSe ction section = (GlobalizationS ection) o;
return section.Culture ;
}
}

Nov 19 '05 #1
0 967

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3456
by: Simon Harvey | last post by:
Hi chaps, Can someone direct me to the necessary class that will allow me to write information into my applications .config file? I know how to read information but I'm sure there must be a way to write out to the config file easily as well. Also, my application doesnt actually have a config file created by default. I thought the VS template would create one automatically but it doesnt. Is it ok just to make one in the form:
2
1276
by: Ashish | last post by:
hi all, i am just curious as to how to access the SessionState section in web.config file programatically and then to possibly change it , are there any .net standard classes to do this ? TIA -ashish
1
3140
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
1
1445
by: justin | last post by:
I have the problem that I need to programatically add new url mappings to the web.config file in an asp 2.0 app. e.g. my code is Dim urlMappings As UrlMappingCollection = urlMappingSection.UrlMappings Dim url_Mapping As UrlMapping Dim y As New UrlMapping("~/myalias", "~/article.aspx?SectionID=45")
4
6114
by: Kaush | last post by:
Hi all, I am creating a webservice to accept SOAP messages, parse the message and send a SOAP response back to the client accessing my web service using WSE-2 in ASP.NET. I am creating a class which derives from "SoapReceiver" class and do the processing here. To register this class by using the HTTP protocol, I am editing the "web.config" file. I am adding an "add" element to this config file as follows: <httpHandlers>
20
2625
by: tomerfiliba | last post by:
hey i've been seeing lots of config-file-readers for python. be it ConfigObj (http://www.voidspace.org.uk/python/configobj.html) or the like. seems like a trend to me. i came to this conclusion a long time ago: YOU DON'T NEED CONFIG FILES FOR PYTHON. why re-invent stuff and parse text by yourself, why the interpreter can do it for you? and anyway, i find this a very ugly format:...
2
1203
by: Tyler | last post by:
I am making a change programatically to web.config. That code works fine. However when I try to save web.config i get the "Access to the path "c:\inetpub\wwwroot\xxx\web.config" is denied. I have given permission to the IUSR_MACHINENAME and the ASPNET acccount. I am not using impersonation and I am running IIS 5.1. Is there something about web.config that won't allow me to save changes programatically? Thanks for your help,
1
4415
by: Jeremy Chaney | last post by:
It appears that my user.config file got corrupted causing my "InitializeComponent" routine to throw an exception "Root element is missing." when I start my app. I figure I can just go into Explorer and delete the file to get things working again, but I'd rather just catch the exception and resolve the error programatically. I tried "Properties.Settings.Default.Reset();" but that just throws the exception too. Does anyone know how I can...
3
10527
by: Jeremy Chaney | last post by:
It appears that my user.config file got corrupted causing my "InitializeComponent" routine to throw the exception "Root element is missing." when I start my app. I figure I can just go into Explorer and delete the file to get things working again, but I'd rather just catch the exception and resolve the error programatically. I tried "Properties.Settings.Default.Reset();" but that just throws the exception too. Does anyone know how I can...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.