How to set breakpoint on [Authorize] Attribute

Is it possible to set a breakpoint on the [Authorize] Atrribute in my class? It has been causing Bad Request errors and I was wondering what inside the [Authorize] Attribute is causing it to do that.

Alternatively, is it possible to overwrite the [Authorize] Attribute and keep the originals functions after my conditions?

I get the BadRequest errors due to the way I am logging in as shown in this question: .NET Core 2.2 Shared Cookie causes Bad Request error when logging in

EDIT: Added Custom Authorize Attribute

public class ExtendedAuthorizeAttribute : AuthorizeAttribute { public async Task OnAuthorizationAsync(AuthorizationFilterContext authorizationFilterContext) { if (authorizationFilterContext.HttpContext.User.Identity.IsAuthenticated == false) { base.Function(); } } } 

2 Answers

  • Is it possible to set a breakpoint on the [Authorize] ? I'm afraid impossible

  • Is it possible to overwrite the [Authorize] Attribute and keep the originals functions after my conditions? Yes, you can call the base class functions by using base.Function()

6

You cannot put a breakpoint inside the default [Authorize] filter, but you could debug the incoming request by providing your own AuthenticateAsync and inspect your request until you find out the problem.

The following snippet is from Authentication Filters in ASP.NET Web API 2.

public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { // 1. Look for credentials in the request. HttpRequestMessage request = context.Request; AuthenticationHeaderValue authorization = request.Headers.Authorization; 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like