JWT Token validation

JWT Token validation

I am trying to perform JWT validation for each action excepting the LogIn and Register actions, but I cannot find a way to do it in action filters, as i need the token and it's on this.Request.Headers. This is the validation method which works fine:

I am trying to perform JWT validation for each action excepting the LogIn and Register actions, but I cannot find a way to do it in action filters, as i need the token and it's on this.Request.Headers. This is the validation method which works fine:

try
{
    JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
    string sToken = token.Substring(7, token.Length - 7);

if (!tokenHandler.CanReadToken(sToken))
{
    return false;
}

JwtSecurityToken jwtToken = tokenHandler.ReadToken(sToken) as JwtSecurityToken;

if (jwtToken == null)
{
    return false;
}

TokenValidationParameters parameters = new TokenValidationParameters()
{
    ValidateIssuer = true,
    ValidateAudience = true,
    ValidateLifetime = true,
    RequireExpirationTime = true,
    ValidAudience = "http://localhost",
    ValidIssuer = "http://localhost",
    IssuerSigningKey = new SymmetricSecurityKey(Encoding.Default.GetBytes(StandardValues.SecretKey))
};

SecurityToken securityToken;
ClaimsPrincipal principal = tokenHandler.ValidateToken(sToken, parameters, out securityToken);

if (principal == null)
{
    return false;
}

} catch (Exception ex) { return false; }

return true;

And I have multiple controllers on which I want to perform the validation. Please let me know how can I perform this validation outside and before the actions, (into an action filter or another way) while sending the token as parameter for validation method.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...

List all users from asp net core identity

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, i will show you How to retrieve and display all the registered application users in asp.net core using the ...

Extend IdentityUser in ASP NET Core

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorials, I will show you how to extend IdentityUser in asp.net core.. Subscribe & Stay Connected! Thank You! ♥ #...