加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET OpenWebConfiguration失败

发布时间:2020-12-16 04:22:20 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试打开W??eb配置,以便我可以加密/解密它但它失败了.我在桌面上的Web Developer 2010 Express上执行此操作,我将网站设置为文件系统.以下是我尝试过的方法. Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current
我正在尝试打开W??eb配置,以便我可以加密/解密它但它失败了.我在桌面上的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读