Skip to content

Running in IIS #16328

Closed
Closed

Description

@stuartm9999

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.

Activity

  1. added
    Source - Docs.ms
    on Dec 27, 2019
  2. guardrex commented on Dec 27, 2019

    @guardrex
    Collaborator

    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.

  3. stuartm9999 commented on Dec 27, 2019

    @stuartm9999
    Author

    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?

  4. Rick-Anderson commented on Dec 27, 2019

    @Rick-Anderson
    Contributor

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

  5. Rick-Anderson commented on Dec 28, 2019

    @Rick-Anderson
    Contributor

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

  6. stuartm9999 commented on Dec 30, 2019

    @stuartm9999
    Author

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

  7. darl0026 commented on Feb 3, 2021

    @darl0026

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

  8. KaptenJon commented on Mar 30, 2022

    @KaptenJon

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Source - Docs.msdoc-enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions