How to trigger openID authorization when Custom Attribute fail in ASP.net core MVC

cebuhax0r 26 Reputation points
2023-01-23T07:25:12.7233333+00:00

Im porting a preveious application written in MVC 5 to ASP.net core MVC, So i created a custom attribute by following this link https://www.c-sharpcorner.com/blogs/authorization-attribute-in-asp-net-core-web-api and we have our own custom validation on it and if it is not allowed previously we just throw HandleUnauthorizedRequest() routine.

We use Keycloak in our authentication, that if we use the [Authorize] attribte in the ported code (ASP.net core mvc 6) it works and redirect to the keycloack login page. However following the tutorial from above, even if I try to throw UnauthorizedResult() or ForbidResult() in AuthorizationFilterContext.Result the page will just stop and will not go back to the Keycloak login page.

How to properly do this?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,078 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,220 questions
0 comments No comments
{count} votes