One of the most powerful features of ASP.NET Core is middleware. It allows you, as an ASP.NET developer, to seamlessly integrate your custom logic directly into the HTTP pipeline. This means you can execute specific code for every incoming request and outgoing response.
For your particular need, checking if a session exists is straightforward. You would simply add an if
statement within your middleware to perform that check.
http://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-9.0