Web Wiz - Solar Powered Eco Web Hosting

ASP.NET Key Storage on Shared Hosting

You have your ASP.NET 8, 7, 6, & 5 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 ASP.NET 5+ application does not have access to the key storage, which breaks features including anti-request forgery tokens.

By default .NET 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 ASP.NET Startup.cs replacing "example\example.com" with your hosting package username and the domain of your website.

public void ConfigureServices(IServiceCollection services)
    .PersistKeysToFileSystem(new DirectoryInfo(@"D:\HostingSpaces\example\example.com\data\keys\"));

Back To Hosting Knowledgebase Menu

Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
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-2024 Web Wiz Ltd. All rights reserved.