AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Running in IIS

Open stuartm9999 opened this issue 6 years ago • 7 comments

I tried this hosting in local IIS and the local secrets were not loaded. When I read the location of the local secrets - %APPDATA%\Microsoft\UserSecrets<user_secrets_id>\secrets.json - I took a punt and changed to IIS Express and it worked. First thing I tried was adding read permissions to IIS worker process to the above directory. This didn't work and I realised that the %appdata% was likely to be different for the IIS worker process anyway. Before reaching for sysinternals filemon - I googled and found that someone else had already done this.. Basically it seems to look in the directory of the application (project) and sure enough if I put my secrets (file) there it works. Not sure if it also looks in - %APPDATA%\Microsoft\UserSecrets<user_secrets_id>\secrets.json - to be honest I didn't even check if APPDATA is set for the IIS worker process. Here's where I got my solution - https://stackoverflow.com/questions/49597408/asp-net-core-2-web-application-isnt-loading-user-secrets-when-debugging-iis-web


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

stuartm9999 avatar Dec 27 '19 12:12 stuartm9999

Hello @stuartm9999 ... Thus far, this is an unsupported scenario outside of perhaps the dev-time support with IIS and VS (as covered by that doc). Recommend that we leave this to Stack Overflow to cover.

guardrex avatar Dec 27 '19 13:12 guardrex

I guess I'm one of the few still using IIS. I'm old and have been caught out on a few occasions by the differences between IIS and IIS express. I believe Azure App service is running IIS so I like to keep close to production - though in this case that desire is not relevant. Anyway more info. Further investigation proved that it works as advertised - using %APPDATA%\Microsoft\UserSecrets<user_secrets_id>\secrets.json but you

  1. Need to know what %APPDATA% is for your IIS worker process - for my desktop it was ""C:\WINDOWS\system32\config\systemprofile\AppData\Roaming"
  2. Need to put the directories containing the secrets there.
  3. Need to grant the IIS worker process read access to these folders.

If it can't find or read the C:\WINDOWS\system32\config\systemprofile\AppData\Roaming<UserSecretsId> then it defaults to the web application directory. I've updated stack overflow as you suggested. Do you think its worth updating the documentation here to simply state that for IIS you need to find the APPDATA environment setting and set the permissions? A simple warning might do?

stuartm9999 avatar Dec 27 '19 15:12 stuartm9999

I'll add a link to this issue to the doc.

Rick-Anderson avatar Dec 27 '19 17:12 Rick-Anderson

@stuartm9999 thanks for the follow up. I like testing against IIS too. Another advantage is it allows remote access to the web app.

Rick-Anderson avatar Dec 28 '19 18:12 Rick-Anderson

Thanks @Rick-Anderson - I had a quick glance at your proposed changes and they seem to make everything clear. Have a great new year.

stuartm9999 avatar Dec 30 '19 09:12 stuartm9999

This is ridiculous, this needs to be fixed. Allowing your website access to a system folder is unacceptable

darl0026 avatar Feb 03 '21 18:02 darl0026

If you have an custom set Identity for the application pool:

  • Set load user profile to true (advanced settings on application pool)
  • Add the user secrets folder to C:\Users<MyCustomUser>\AppData\Roaming\Microsoft\UserSecrets<UserSecretId>\secrets.json

KaptenJon avatar Mar 30 '22 08:03 KaptenJon