1

I have added [Authorize] attribute over my BaseController. Without JWT token it shows 401 error, I need to customize that 401 error. I need to understand at which place the Application throws 401 error. Can someone please help me.

1 Answer 1

1

There are several ways to customize this behavior, but I think the most straightforward one is to write a custom middleware.

// Startup.Configure method

app.UseRouting();

app.Use(async (context, next) =>
{
    await next();

    if (context.Response.StatusCode == (int)HttpStatusCode.Unauthorized)
    {
        await context.Response.WriteAsync("Token Validation Has Failed. Request Access Denied");
    }
});

app.UseAuthentication();

app.UseAuthorization();

app.UseEndpoints();

Sign up to request clarification or add additional context in comments.

1 Comment

Can you suggest me with some blogs or videos to learn and Implement it @Martin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.