How To Manage User Secrets In Asp.net Core [2026 Update]

Once initialized, secrets are stored in a secrets.json file located in your user profile folder (e.g., %APPDATA%\Microsoft\UserSecrets\ on Windows or ~/.microsoft/usersecrets/ on macOS/Linux).

public class MyController : ControllerBase { private readonly IConfiguration _config; public MyController(IConfiguration config) => _config = config; public IActionResult Get() { var apiKey = _config["ServiceApiKey"]; // Retrieves the secret return Ok(); } } ``` ### Key Best Practices * **Development Only:** User secrets are **not encrypted** and are only intended for local development. * **Production Security:** Never use Secret Manager for production. Instead, use more secure providers like [Azure Key Vault](https://learn.microsoft.com/en-us/aspnet/core/security/key-vault-configuration) or [environment variables](https://microsoft.com). * **Source Control:** Ensure your `secrets.json` file path is never added to `.gitignore`, though it should already be safe since it lives outside the project folder. Use code with caution. Copied to clipboard How to manage user secrets in ASP.NET Core - InfoWorld

Adding them directly to the secrets.json file that opens after you select Manage User Secrets . Via .NET CLI: Use the set command to add individual keys:

Storing sensitive data like API keys, database connection strings, or passwords directly in your code or appsettings.json is a major security risk. If you accidentally commit these files to source control (like GitHub ), anyone with access to the repository can see them.

Right-click the project in Solution Explorer and select Manage User Secrets .

РЕГИСТРИРУЙСЯ С ПОМОЩЬЮ E-MAIL И ПОЛУЧАЙ СООБЩЕНИЕ
О СКИДКАХ И АКЦИЯХ
Для улучшения работы сайта provelo.ru и его взаимодействия с пользователями мы используем файлы cookie. Продолжая работу с сайтом, Вы разрешаете использование cookie-файлов. Вы всегда можете отключить файлы cookie в настройках Вашего браузера.
Понятно