Reputation: 2865
I'm running into a problem where UserSecrets returns my secret on Mac, but not windows. I followed https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?tabs=visual-studio
On windows, when I try to get the secret: Configuration["ConnectionStrings:Production"]
it returns null.
I have the secrets.json
file saved at C:\Users\username\AppData\Roaming\Microsoft\UserSecrets\<userSecretsId>
I can't figure out why it won't work on Windows, while it works perfectly on Mac. Any help is greatly appreciated.
It might be worth noting this is on a Windows Server
I'm wondering now if %AppData%
is different in the context of IIS?
I think this thread is the right direction but none of the solutions work for me
Upvotes: 3
Views: 4658
Reputation: 724
The IIS ApplicationPoolIdentity should have it's own user profile folder, which is not the same as your user folder.
To find it, navigate to C:\Users, and you should see folders named for the application pools, so for an App Pool named ".NET v4.5" there should be a user folder called ".NET v4.5". Under that folder you should be able to follow the rest of your breadcrumb through the AppData folder and create the "\AppData\Roaming\Microsoft\UserSecrets" folder if it doesn't exist.
If that doesn't work or if you don't see user folders for the Application Pools, open up IIS Manager, select the Application Pool you're running under, then open Advanced Settings (link on the right hand side)
After opening the Advanced Settings, scroll down to the Process Model section and you should see a configuration for "Load User Profile", and make sure the value is set to True. Default is true in Windows 10, but depending on how you've done config prior versions of Windows defaulted to False which would make the secrets not available.
Upvotes: 4