用户机密文件在 asp.net core 6 中被忽略

发布于 2025-01-18 03:44:34 字数 220 浏览 1 评论 0原文

我有两个针对 .net 6 的项目,并且没有任何使用用户机密的显式声明(我记得,在以前的版本中需要使用 AddUserSecrets())。虽然,一个项目从 secrets.json 获取正确的配置,但另一个项目 - 尝试从 appsettings.json 获取它。

所以,我想知道,这是什么问题? .net 6 中的行为如何改变?

I have two projects targeted .net 6 and there are no any explicit declarations for using user secrets (I remember, it was required in previous versions to use AddUserSecrets()). Though, one project gets the right config from secrets.json, but another one - tries to get it from appsettings.json.

So, I'm wondering, what's the issue? How the behavior was changed in .net 6?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧 2025-01-25 03:44:34

在.net6,webapplication.createbuilder初始化了带有预配置默认值的WebApplicationBuilder类的新实例。初始化的WebApplicationBuilder(Builder)提供默认配置,并在环境名称开发时调用AddUserSecrets。

只要您使用webhost.createdeedefaultbuilder方法初始化Web应用程序,ASP.NET Core会自动从.NET6中的secrets.json文件拾取您的配置。如果您手动或不手动初始化应用程序。

请参阅 /a>

In .Net6, WebApplication.CreateBuilder initializes a new instance of the WebApplicationBuilder class with preconfigured defaults. The initialized WebApplicationBuilder (builder) provides default configuration and calls AddUserSecrets when the EnvironmentName is Development.

As long as you initialize your web application using the WebHost.CreateDefaultBuilder method, ASP.NET Core automatically picks up your configuration from the secrets.json file in .Net6. If you initialize your application manually or not .Net6, make sure to call the AddUserSecrets-method.

refer to this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文