C# · 12月 22, 2021

c# – 如何以编程方式读取web.config值?

我使用asp.net和c#4.
我有一个Web.Config文件 <globalization culture=”auto:fr” uiCulture=”fr”/>

我想在Code Behind中以编程方式在新变量中获取此值.

var test = …….

如何获得文化价值?

解决方案感谢您的回答:

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;