Search code examples
webapi.net-7.0user-secret

User Secrets not loading with WebApplication.CreateBuilder(args)


My understanding from the Microsoft documentation is the userSecret configuration is supposed to be automatically created by the WebApplication.CreateBuilder() while in the development environment. This is not true for my current WebAPI .net7 application. I have run the init command and populated the secrets file. Any ideas on why the userSecrets would be missing from the configuration sources?


Solution

  • From the documentation:

    The initialized WebApplicationBuilder (builder) provides default configuration and calls AddUserSecrets when the EnvironmentName is Development.

    Ensure that your environment is set to Development. This is usually done via the ASPNETCORE_ENVIRONMENT env variable for web apps.