c# - 如何在不使用 HttpContext 的情况下获取 Web 应用程序的当前配置?

标签 c# configuration web-config

我需要在我的 Web 应用程序中获取当前配置的实例。我发现我可以通过以下方式获取:

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

但是在我项目的某些部分我没有HttpContext 所以我需要在不使用HttpContext 的情况下获取配置实例。

最佳答案

你是对的 Lubochkn ~ 成功了......

_webConfigurationManager = WebConfigurationManager.OpenWebConfiguration("~");

关于c# - 如何在不使用 HttpContext 的情况下获取 Web 应用程序的当前配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8052677/

相关文章:

c# - ConfigurationManager.AppSettings 找不到设置

c# Windows Service Console.Writeln 收藏

java - JSON 中 map 的带点路径 (Java)

c# - 从 C++/Java/C# 代码调用 C 方法?

azure - 有关如何使用 ARM 为 azure 中的无服务器应用程序设置持续交付管道的示例

.net - 如何基于构建配置有条件地部署app.config?

asp.net - 修改 web.config 时如何防止 ASP.NET 应用程序重新启动?

c# - 无法加载文件或程序集 'log4net

c# - 我可以用 null 初始化一个对象吗?

c# - 使用委托(delegate)来模拟连接的对象