草庐IT

webconfigurationmanager

全部标签

c# - 以编程方式访问 web.config 的 <compilation/> 部分?

有什么方法可以访问在web.config文件中标记?我想检查文件中的“debug”属性是否设置为“true”,但我似乎不知道该怎么做.我试过使用WebConfigurationManager,但这似乎不允许我访问部分。更新:我知道我可以像加载XML文档一样轻松地加载文件并使用XPath,但我希望框架中已经有一些东西可以为我做这件事。似乎会有一些东西,因为已经有获取应用程序设置和连接字符串的方法。我也尝试过使用WebConfigurationManager.GetSection()方法有几种:WebConfigurationManager.GetSection("compilation"

c# - 使用 .Net 配置框架加载具有所需子 ConfigurationElement 的 ConfigurationSection

我有一个控制台应用程序试图从web.config文件加载CustomConfigurationSection。自定义配置部分有一个必需的自定义配置元素。这意味着当我加载配置部分时,如果该配置元素不存在于配置中,我希望看到异常。问题是.NET框架似乎完全忽略了isRequired属性。因此,当我加载配置部分时,我只是创建了一个自定义配置元素的实例并将其设置在配置部分。我的问题是,为什么会这样?我希望GetSection()方法触发ConfigurationErrors异常,因为配置中缺少必需的元素。这是我的配置部分的样子。publicclassMyConfigSection:Config

c# - System.Web.Configuration.WebConfigurationManager 和 System.Configuration.ConfigurationManager 之间的行为差​​异

我在带有ASP.NET网站的测试服务器上遇到了一些问题。我傻了,有了家默认网站的目录指向了错误的位置。当我尝试时:ConfigurationManager.ConnectionStrings["connectionString"];它返回了null,但是usingSystem.Web.Configuration;/*...*/varrootWebConfig=WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);WebConfigurationManager.OpenWebConfiguration(

c# - CloudConfigurationManager 与 WebConfigurationManager 对比?

在Azure网站中,我总是使用以下代码从配置的应用程序设置中获取一些值:stringproperty=WebConfigurationManager.AppSettings["property"];就在几天前,我偶然发现了CloudConfigurationManager,通过它我可以获得如下属性:stringproperty=CloudConfigurationManager.GetSetting("property");尽管CloudConfigurationManager似乎更适合云使用,但我从未对WebConfigurationManager有任何问题。我应该使用CloudCo

c# - WebConfigurationManager.AppSettings 的缓存?

我有很多读取我的Web配置文件的请求variable=WebConfigurationManager.AppSettings["BLAH"]WebConfigurationManager.AppSettings是每次都从磁盘读取,还是缓存在内存中?如果每次都从磁盘读取它,那么我想我需要将该变量移动到静态变量以提高我的应用程序性能。 最佳答案 配置设置缓存在内存中,每次调用此函数时不会解析web.config。 关于c#-WebConfigurationManager.AppSetting