开发者

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("/");
G开发者_高级运维lobalizationSection 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.


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

var globalizationSection = 
        WebConfigurationManager.GetSection("globalization") as GlobalizationSection;


You might need to import the System.Configuration and System.Web.Configuration namespaces to do this, but you can do something like this:

//and here is the code to get the section
Configuration config = WebConfigurationManager.OpenWebConfiguration("/");     
GlobalizationSection section = config.GetSection("globalization") as GlobalizationSection;


Check out http://msdn.microsoft.com/en-us/library/system.web.configuration.globalizationsection.aspx

It looks like you need to include/use System.Web.Configuration.GlobalizationSection

Then .Culture http://msdn.microsoft.com/en-us/library/system.web.configuration.globalizationsection.culture.aspx#Y300

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜