gpt4 book ai didi

asp.net - 无法从 App.Config 检索 key

转载 作者:行者123 更新时间:2023-12-04 22:17:06 25 4
gpt4 key购买 nike

在我的 WAP 项目中,我引用了另一个 C# 项目(非 Web)。在那个 C# 项目中,我有一个 app.config 并将其重命名为 [projectName].config

然后我尝试从我的 [project].config 中从我的 C# 项目中的一些代码中获取一个 key ,但找不到它:

return ConfigurationManager.AppSettings["somekey"]

所以我想知道为什么它不能读取我的 app.config。我认为 ConfigurationManager 能够从 Web 项目的 web.config 和我引用的项目中的 [projectName].config (app.config) 文件中读取 key ?

最佳答案

ConfigurationManager 将读取 the configuration of the application's host 。在您的情况下,Web 应用程序是应用程序的主机 - 因此,调用 ConfigurationManager 将从您的 web.config 读取 - 即使您从引用的 dll 调用 ConfigurationManager。

如果您的 Web 应用程序引用了一个 dll,那么该 dll 应该从 web.config 中获取其配置。这是应用程序的最佳选择。如果 dll 被多种类型的应用程序引用,则 config 中的设置可能需要不同。

关于asp.net - 无法从 App.Config 检索 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2165413/

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