AspNet Core using in memory repo for data protection when running in IIS

mrahhal picture mrahhal · May 8, 2016 · Viewed 10.9k times · Source

I'm running a production server (Windows Server 2012) with an AspNet Mvc Core RC1 website.

I'm seeing the following in the logs:

Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.

After inspecting the source code for DataProtection, I tracked the problem to the following method call:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

This is probably returning null on the server for some reason. I don't have any special custom configuration in place and I've read the docs so I thought the default would work.

I think the problem is with the IIS website not running in a certain user's context but I have no idea how to confirm or fix this. My website is configured with its own pool.

As an aside: the result of running an in memory repository for storing keys causes them to recycle whenever the application exits which is very annoying and not even intended for use in production environments.

Answer

mrahhal picture mrahhal · May 11, 2016

User profile should be loaded in IIS configuration.

Open IIS, right click on Application Pools then Advanced Settings. And set "Load user profile" to true. Restart your app and it should work perfectly.