How To Prevent Sign Out After ASP.NET Core 2.0 Deployment



Last updated: January 28th, 2024

Problem

If you are signed in to an ASP.NET Core 2.0 application and then re-deploy (or just start/ stop) the application, the user is signed out and must then sign back in. This is very annoying for users.

Quick Solution

Based on this Stack Overflow post. The DirectoryInfo will create the folder at the root path of the server and the application name is the name of the website in the IIS Manager.

Note: You will need to have the server first running this code before signing in. After this code is running, the key will be persisted to the server and the subsequent deployments should not sign the user out until the lifetime expires. Additionally, be aware that the key persisted to the file is unencrypted.

Advanced Solution

There are other ways to deal with the keys being persisted. This may be important when your web servers cannot share the same directory on a single server. For more advanced situations, which require multiple servers and encryption, look at: .NET Core cookie authentication middleware, load balanci.ng and the data protection system.


Comments

No Comments

Post Comment

Prove you are human 3 + 10 =



Join my email list!



ryan
About Me

With 15 years in tech, I've excelled as a senior software engineer, specializing in ASP.NET, C#, SQL, Azure, and front-end technologies. I've led diverse projects across various sectors, from startups to global corporations, particularly during my decade in the San Francisco Bay Area.


Sign Up With SoftSys Hosting! (My host)