如何读取web.config中的System.Web节 [英] How to read system.web section from web.config
本文介绍了如何读取web.config中的System.Web节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
应该是简单的,但无论我尝试返回空值:
Should be simple, but whatever I try returns null:
const string key = "system.web";
var sectionTry1 = WebConfigurationManager.GetSection(key);
var sectionTry2 = ConfigurationManager.GetSection(key);
我敢肯定,我以前做过这个。
I'm sure I have done this before.
我使用MVC,如果这有差别。
I am using MVC if this makes a difference.
推荐答案
正在白痴 - System.Web程序是不是一个配置部分,但一个配置组。如果我改变的关键是一个实际的部分,然后这两种方法很好地工作。下面是使用ConfigurationManager中的一项:
Was being an idiot - system.web is not a config section but a config group. If I change the key to an actual section, then both methods work fine. Here's the one using ConfigurationManager:
const string outputCacheSettingsKey = "system.web/caching/outputCacheSettings";
var outputCacheSettingsSection = ConfigurationManager.GetSection(outputCacheSettingsKey) as OutputCacheSettingsSection;
这篇关于如何读取web.config中的System.Web节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文