Sri Ram

Sri Ram

  • 1.6k
  • 173
  • 99.6k

How to do common validation for every web server request ?

May 17 2020 10:51 PM
We have an ASP.NET Core 3.1 MVC web app that uses cookie authentication feature. 

When user logs into the app,  we get a "SessionId" from database(specific to logged-in user) and add it to ClaimsPrincipal/ClaimsIdentity object. 
 
I want to add a common validation that validates this "SessionId" against the database for every subsequent web server request. i.e. have to validate this for each action method call in addition to the standard cookie authentication.
 
In the regular ASP.NET Framework based apps, we use to keep this logic in Global.asax and retain the values as part of Session object. 
 
In case of ASP.NET Core, what is the equivalent feature or options we have to this common validation for every server request and what is the right way of implementing this?
 
Experts, please advice. 

Answers (1)