ASP.NET OpenWebConfiguration失败

use*_*521 8 asp.net web-config

我正在尝试打开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);
Run Code Online (Sandbox Code Playgroud)

每次出现错误时:加载配置文件时出错:无法映射路径'/'.

有任何想法吗?

Osc*_*car 17

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

var section = WebConfigurationManager.GetSection("mySection");
Run Code Online (Sandbox Code Playgroud)

只是为了让您知道,正确的参数是:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
Run Code Online (Sandbox Code Playgroud)

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


Ain*_*llo 9

以管理员身份运行Visual Studio.干杯! :d

  • 这有什么用? (2认同)
  • 有同样的问题,但当我试图以管理员身份运行我的视觉工作室时,它就像一个奇迹.:) (2认同)