Reputation: 1762
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?
Upvotes: 4
Views: 6890
Reputation: 9092
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
Upvotes: 10