用户机密文件在 asp.net core 6 中被忽略
我有两个针对 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在.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