ASP.NET OpenWebConfiguration 失败

标签 asp.net web-config

我正在尝试打开 Web 配置,以便可以对其进行加密/解密,但它失败了。我在桌面上的 Web Developer 2010 Express 上执行此操作,我将网站设置为文件系统。以下是我尝试过的方法。

Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);

Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

Configuration config = WebConfigurationManager.OpenWebConfiguration("/web.config");

Configuration config = WebConfigurationManager.OpenWebConfiguration(/AppNameHere);

每次我收到错误:加载配置文件时发生错误:无法映射路径'/'。

有任何想法吗?

最佳答案

如果您尝试从应用程序中打开 web.config,则无需打开它,只需使用:

var section = WebConfigurationManager.GetSection("mySection");

只是为了让您知道,正确的参数是:
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");

见:http://msdn.microsoft.com/es-es/library/system.web.configuration.webconfigurationmanager(v=vs.100).aspx

关于ASP.NET OpenWebConfiguration 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936432/

相关文章:

deployment - 将 dll 的配置文件移动到调用 dll 的应用程序

asp.net - 连接字符串应存储在n层asp.net应用程序中的何处

c# - 安全性:在 web.config 或代码中保存加密 key

.net - 验证 ASP.NET Ajax 扩展的安装

c# - MongoDB 和 C# 数据源

c# - 在 MasterPage 中使用 javascript 验证文本框

c# - 在 asp.net 中创建连接字符串/连接到数据库?

c# - 可以在开发机器的 web.config 中加密 ConnectionString 并部署在服务器上吗?

c# - 在数据注释验证错误消息中隐藏底层属性名称

asp.net - ASP.NET 中的 RangeValidator 问题