Web Wiz - Solar Powered Eco Web Hosting


ASP.NET Core Key Storage on Shared Hosting


You have your .NET Core application you have built with Visual Studio running locally but when you publish your application to shared web 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\"));
}



Back To Hosting Knowledgebase Menu

Become a Fan on Facebook Follow us on Twitter Connect with us on LinkedIn Community Forums Web Wiz Blogs Web Wiz News
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2020 Web Wiz Ltd. All rights reserved.