Repository navigation
Description
Problem
This fails if you are debugging on IIS and not using IIsExpress. Reasons:
- current profile being used in iis would be the user profile for the apppool
- load user profile in app pool must be turned on
- The Visual Studio manage user secrets and dotnet user-secrets set both touch the user's %APPDATA% that is running the tool so this means you are not modifying the correct secrets.json
The WHOLE point of having it write to an out of repo file is that you didn't want to check in the secrets into the repo.
Fix
Add --iis and --iisDebugProfile options to dotnet user-secrets set that tell it to look up the correct site/apppool and determine the correct user profile path to write the secrets.json. Along with adjusting the secrets provider to write settings like the following sample if --iis was used so that just in case same profile was used in multiple sites you still have secret ID specific settings. iisDebugProfile woulld allow you to pick the right site from the launchsettings.json in the project.
{
"113dbdab-7d0c-40d8-9793-c86e77ebdbc8":{
"secret 1 Path":"Secret 1 Value",
"secret 2 Path":"Secret 2 Value"
}
}
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 9c99993c-c983-6fda-6c3a-ce4ec8c1d5db
- Version Independent ID: ba688ac2-e90e-fce5-f60d-40c2553c3efd
- Content: Safe storage of app secrets in development in ASP.NET Core
- Content Source: aspnetcore/security/app-secrets.md
- Product: aspnet-core
- Technology: aspnetcore-security
- GitHub Login: @tdykstra
- Microsoft Alias: riande
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
Activity
vbjay commentedon Sep 15, 2023
See #16328 for related and mentioned in article. I frankly think a section in the docs should talk about this issue instead of an easily missed link. Something like
Using Secrets in IIS vs IISExpress
If running in IIS, the fileprovider looks in the website folder. The recommendation is to create a secrets.json file in the project and add to .gitignore to prevent checking in the secrets.
I still think the tooling could be better to manage the correct secrets.json file.
Rick-Anderson commentedon Sep 19, 2023
We're a documentation repo. Feel free to open a suggestion issue at https://github.com/dotnet/aspnetcore/tree/main/src/Tools/dotnet-user-secrets
Rick-Anderson commentedon Sep 19, 2023
Why do you need to check in secrets to the repo?
vbjay commentedon Sep 19, 2023
Re read what I said. You are not reading what I said correctly.
vbjay commentedon Sep 19, 2023
Thanks. I'll do that.