ASP.NET Core 5.0 - User Secrets

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": "smtp.gmail.com",
  "MailPort": 465,
  "SenderName": "Sender Name",
  "SenderEmail": "senderemail@gmail.com",
  "Password": "GmailPassword",
  "PasswordEncrypted": false,
  "BannerBackcolor": "#FF0000",
  "BannerColor": "#FFFFFF",
  "BannerText": "User Secrets",
  "EmailSignature": "Email Signature",
  "SupportName": "Secret Support",
  "SupportEmail": "supportemail@gmail.com",
  "AdminEmail": "adminemail@gmail.com"
}

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:

%APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets.json

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.

<UserSecretsId>ken-gmail-20210801</UserSecretsId>

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.
Processing...
Something went wrong. Please try again.
Contribute to enjoy content without advertisments.
You can contribute without registering.

Comments(0)

Loading...
Loading...

Not accepting new comments.

Submit your comment. Comments are moderated.

User Image.
DisplayedName - Member Since ?