secrets.json holds private, development-specific settings for an ASP.NET Core application. It lives outside the project directory, so a developer can keep a local database connection string out of the project’s appsettings.json files. section 4.3.4
To set it up for the board-game API:
- In Visual Studio, right-click the project’s root folder and choose Manage User Secrets. Visual Studio adds a UserSecretsId to the project file, creates secrets.json under the matching local UserSecrets folder, and opens it for editing. section 4.3.4
- Add ConnectionStrings:DefaultConnection with the development database connection string. Replace the sample password with the password for your database login. section 4.3.4
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=MyBGList;
User Id=MyBGList;Password=MyS3cretP4$$;
Integrated Security=False;MultipleActiveResultSets=True;
TrustServerCertificate=True"
}
}
This JSON uses the ConnectionStrings and DefaultConnection keys expected by GetConnectionString("DefaultConnection") in Program.cs. Use your own database credentials rather than the sample password. section 4.3.4
Keys in secrets.json override matching appsettings*.json keys and add keys that are absent. The API can therefore retrieve DefaultConnection through its usual configuration call. For production, create appsettings.Production.json on the server with the corresponding keys and production values; do not add that credentials file to the shared project. section 4.3.4 section 12.1.4 section 12.3.7
