我正在尝试打开 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/