Azure Cache Redis as Session Store for ASP.NET Core Application

2022-04-30 asp.net-coreazure

When use Cookie authentication schema in ASP.NET core applications, session data by default is saved in client as Cookies. If the session data (incl. user claims) are big (more than 4090 characters), it can be split into multiple chunks. You can notice that via application identifier cookie:

  • .AspNetCore.Cookies: chunks-2
  • .AspNetCore.CookiesC1: XXX
  • .AspNetCore.CookiesC2: XXX

Instead of storing session data in client cookies, we can also store the session data in any store that implements ITicketStore. It can be databases, memory cache or distributed memory cache like Redis.

This diagram shows a simple solution of using Azure Cache Redis as session store. The following links can be referenced to implement a solution like this.

References

Cookie size and cookie authentication in ASP.NET Core - Honza’s Blarg (hajekj.net)

ChunkingCookieManager Class (Microsoft.AspNetCore.Authentication.Cookies) | Microsoft Docs

Session in ASP.NET Core | Microsoft Docs

Matteo's Blog - Implementing a custom ITicketStore for ASP.NET Core Identity (ml-software.ch)

Using Redis Cache for session data storage in ASP.NET Core - Joonas W's blog

ASP.NET Core Applications
[Not supported by viewer]
Azure Cache Redis
[Not supported by viewer]
Cookie Authentication
[Not supported by viewer]
«ITicketStore»
Session Store
[Not supported by viewer]
Cookies
(Session ID)
[Not supported by viewer]
Icon-web-41 public:true sdk:MsPortalFx.Base.Images.Polychromatic.Website() category: Compute, Containers, App Services image/svg+xml Icon-web-41 Icon-databases-137 public:true sdk:false category: Databases image/svg+xml Icon-databases-137 MsPortalFx.base.images-15 public:true sdk: MsPortalFx.base.images.Polychromatic.Browser() category: General image/svg+xml MsPortalFx.base.images-15