About dotnet user-secret

Liu, Tonghe 21 Reputation points
2022-02-23T21:01:30.187+00:00

Hi,

I am using "dotnet user-secret" to store our apikey. Our situation is, we have several appsetting files for different environment (for example: appsetting.developing.json, appsetting.production.json .....). I look through the document, the command "dotnet user-secrets set -c " may solve this issue. But in practice, seems "-c" does not store the apikey into separate "UserSecretId". The command I am using is

dotnet user-secrets set -c Development "id" "13“

and then

dotnet user-secrets set -c Production "id" "14"

But when I check the csproj file, there is only one "UserSecretId" and it only stores the value "14". So "-c" actually doesn't work. Could you please tell me how can I set user secrets for multiple environments?

Thanks in advance for your attention and help,
Best regards,
Leo

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 30,126 Reputation points
    2022-02-23T21:43:53.647+00:00

    According to the documentation, user secrets are only used in the local development machine so sensitive data is not committed to source control.

    You get to decide how the configuration is stored when deploying to different environment.

    Use multiple environments in ASP.NET Core

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2022-02-24T02:53:19.063+00:00

    Hi @Liu, Tonghe ,

    As AgaveJoe said, the user secrets are only used in the local development machine.

    To set user secrets for multiple environments, you can store them in different environment appsetting.json file. But for the security reason, I suggest you use Azure Key Vault to store the user secrets.

    Azure Key Vault safely stores app secrets for ASP.NET Core apps. For more information, see Azure Key Vault configuration provider in ASP.NET Core.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.