Episode 16: Using Redis for Distributed User Sessions in ASP.NET Core
• Jordan Griffin
ASP.NET session storage is useful for storing state across page views. In single server situations it’s simple to set up because ASP.NET supports in-memory session out of the box. In-memory sessions stop working as soon as there is more than one server. Most production environments have more than one server so the session issue needs to be dealt with.
There are two options for sessions in a web farm. First, a load balancer can be used to lock each user on a specific box (so-called “sticky sessions” or “session affinity”). This lets us continue to use in-memory session. The second is switching from in-memory to distributed session storage.
We will use a distributed session using Redis because we have existing Redis infrastructure and we don’t want a complex load balancer added to the mix.
Install the StackExchange Redis Distributed Cache Package