我使用 asp.net 和 c# 4。 我有一个 Web.Config 文件
<globalization culture="auto:fr" uiCulture="fr"/>
我想在代码隐藏中以编程方式在新变量中获取此值。
var test = .......
如何获得文化值(value)?
解决方案感谢您的回答:
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.
最佳答案
这是一个GlobalizationSection
, 所以你可以通过
var globalizationSection =
WebConfigurationManager.GetSection("globalization") as GlobalizationSection;
关于c# - 如何以编程方式读取 web.config 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7230950/