You have your ASP.NET Core (5 & 6) application you have built with Visual Studio running locally but when you publish your web application to shared hosting is stops working with errors that include;
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
The problem is that the .NET Core application does not have access to the key storage, which breaks features including anti-request forgery tokens.
By default .NET Core key storage will use the User Profile and the Windows Registry on the server for the key storage. In a multi-tenancy environment such as shared hosting write access to the Registry is not available for security reasons. This problem can be fixed by moving key storage to the websites private 'data' folder located above the websites root.
The example below would be placed into the .NET Core Startup.cs replacing "example\example.com" with your hosting package username and the domain of your website.
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"D:\HostingSpaces\example\example.com\data\keys\"));
}
