AddUserSecrets loads User Secrets into ASP.NET Core configuration during local development, keeping sensitive values outside the project folder and source control. section 10.2.3
Use the extension with these practical safeguards:
- Register it only when the environment is Development; production should use environment variables or Azure Key Vault. section 10.2.3
- Call AddUserSecrets<Program>(); Program identifies the assembly containing the UserSecretsId project property. section 10.2.3
- Initialize User Secrets and add values with the .NET CLI, or edit the external secrets.json file directly. section 10.2.3
Load secrets only during development
if (builder.Environment.IsDevelopment()) { builder.Configuration.AddUserSecrets<Program>(); } The provider uses the UserSecretsId from the project file to locate secrets.json. The default WebApplicationBuilder configures this behavior correctly by default. section 10.2.3
