6

When I run my asp.net 3.1 app on my VS 2019, it is working fine and no problem. After I published to my local IIS , I got this problems ( Using an in-memory repository. Keys will not be persisted to storage. Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.). I tried to to set Load User Proifle on IIS advanced setting also. I tried this article Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. But my problems is not solved. Any advice or guidance would be greatly appreciated.

Thanks amy

3

1 Answer 1

5

I ran into these error messages in our logs as well, but in our case that's because we're running ASP.NET Core on Linux, and there's neither IIS nor a HKLM registry on Linux.

The main symptom is that users would get authentication errors when we deployed a new version of the server. That's because the keys were stored in memory as the error message says, and when redeploying the application, the keys would be lost, and new ones get re-generated upon launching the new version of the application.

The solution was to just persist the keys to local storage. In your startup.cs file, try adding these lines:

using Microsoft.AspNetCore.DataProtection;

public void ConfigureServices(IServiceCollection services) {
    // other config code

    services.AddDataProtection()
        .PersistKeysToFileSystem(new DirectoryInfo(@"C:\someFolder\"));
    // config code for authentication
    // other config code
}

Since I'm testing locally on a windows machine, "someFolder" is actually a configured value read from appsettings.json and appsettings.Development.json. The path on Linux is different, and the processes that runs the .NET application will need to own and have read and write permissions for the process (www-data on ubuntu with nginx)

Be aware that persisting the keys to the file system automatically removes the encryption, but encryption can be added back.

For the MS documentation on these:
https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers?view=aspnetcore-5.0&tabs=visual-studio

https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-encryption-at-rest?view=aspnetcore-5.0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.