ASP.NET Core 5.0 - User Secrets

Download KH Authenticator

KH Authenticator App Icon
.NET MAUI App for Windows and Android
Online Registration and Authentication
No Password Or Email Address Required!
Certified Providers
KenHaggerty.Com Users Without Passwords Users With Passwords Users Without Identity

This article will describe the implementation of the project's User Secrets or secrets.json. I will assume you have downloaded the ASP.NET Core 5.0 - SMTP Settings Tester Project. Registered users can download the source code for free at Manage > Assets.

SMTP Settings Tester Project and Article Series

This project implements Bootstrap v5, Bootstrap Native, and the KenHaggerty. Com. SingleUser NuGet package which provides log in and log out pages for a single user to access the Admin pages. jQuery has been removed. I created a topic, ASP.NET Core 5.0 - SMTP Settings Tester Project for discussions. More details and screenshots at ASP.NET Core 5.0 - SMTP Settings Tester Project. The details page includes the version change log.

One of the best reasons to use the runtime TOpions of EmailSettings is User Secrets. There is plenty of good documentation on the User Secrets configuration and setup. See MSDocs - Safe storage of app secrets in development in ASP.NET Core. This article will demonstrate applying, naming, and sharing User Secrets.

Use the Secret Manager tool to create a configuration folder named with a random GUID and an empty secrets. json file by right clicking on the project name then click Manage User Secrets.

Manage User Secrets.

Add an EmailSettings section to secrets. json with your email server settings. If you want to use Gmail for SMTP, you must allow less secure app access to the Google account.

"EmailSettings": {
  "Configured": false,
  "Timeout": 30000, // default = 120000 = 2 minutes
  "MailServer": "",
  "MailPort": 465,
  "SenderName": "Sender Name",
  "SenderEmail": "",
  "Password": "GmailPassword",
  "PasswordEncrypted": false,
  "BannerBackcolor": "#FF0000",
  "BannerColor": "#FFFFFF",
  "BannerText": "User Secrets",
  "EmailSignature": "Email Signature",
  "SupportName": "Secret Support",
  "SupportEmail": "",
  "AdminEmail": ""

The Secret Manager tool hides implementation details, such as where and how the values are stored. You can use the tool without knowing these implementation details. The values are stored in a JSON file in the local machine's user profile folder:


Where <user_secrets_id> is the UserSecretsId value specified in the project file.

Edit Project File UserSecretsId.

I use the same secrets. json configuration for the development of multiple projects. I manage different User Secrets configurations by naming them with a friendly name and last update date like ken-gmail-20210801. I locate the secrets. json file and rename the containing folder. Then I update the UserSecretsId value specified in the project file.


I share the named User Secrets across multiple projects by adding or updating the UserSecretsId.

Ken Haggerty
Created 08/02/21
Updated 08/07/21 01:19 GMT

Log In or Reset Quota to read more.

Article Tags:

Email Json
Successfully completed. Thank you for contributing.
Contribute to enjoy content without advertisments.
Something went wrong. Please try again.



Not accepting new comments.

Submit your comment. Comments are moderated.

User Image.
DisplayedName - Member Since ?