gpt4 book ai didi

asp.net - 如何通过ConfigurationManager找到配置文件位置?

转载 作者:行者123 更新时间:2023-12-02 14:56:50 25 4
gpt4 key购买 nike

如何通过ConfigurationManager查找配置文件位置?

我在代码中有 ConfigurationManager 类,并且正在调试它。我想知道它指向哪个配置文件(web.config 或 app.config 等)。

ConfigurationManager 上是否有任何属性或方法可以帮助解决此问题?

最佳答案

配置文件本身由 Configuration 表示目的。要获取此对象,请运行以下命令:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

然后可以通过config.FilePath查看文件路径。

更新。正如 Schadensbegrenzer 所指出的那样对于网络应用程序,您将需要另一个代码来加载配置文件:

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

关于asp.net - 如何通过ConfigurationManager找到配置文件位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23930126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com