Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read programmatically web.config values?

I use asp.net and c# 4. I have a Web.Config file

<globalization culture="auto:fr" uiCulture="fr"/>

I want to get this value in a new variable programmatically in Code Behind.

var test = .......

How to get value for culture?

Solution Thanks to your Answers:

Configuration config = WebConfigurationManager.OpenWebConfiguration("/");
GlobalizationSection section = (GlobalizationSection)config.GetSection("system.web/globalization");

OpenWebConfiguration("/"); // Point to Physical path for the Web.Config file (Useful when using Routing).

GetSection("system.web/globalization"); // Get the globalization section within the system.web node.
like image 205
GibboK Avatar asked Aug 29 '11 13:08

GibboK


1 Answers

It's a GlobalizationSection, so you can get at it via

var globalizationSection = 
        WebConfigurationManager.GetSection("globalization") as GlobalizationSection;
like image 187
Russ Cam Avatar answered Oct 09 '22 12:10

Russ Cam