Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

user secrets file gets ignored in asp.net core 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?

like image 957
anatol Avatar asked Oct 18 '25 13:10

anatol


1 Answers

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

like image 105
Qing Guo Avatar answered Oct 20 '25 17:10

Qing Guo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!