user145610
user145610

Reputation: 3025

WEB API OnAuthorization is Called Twice

I'm developing web API solution for authorization, we decorated each controller action method with the BasicHttpAuthorizeAttribute class with inherits from AuthorizeAttribute.

public class BasicHttpAuthorizeAttribute : System.Web.Http.AuthorizeAttribute

For every request, I see OnAuthorization method is called twice. when I check the callstack, all the request is made by same thread/processId. I'm using UnityContainer. I registered by Custom Authorize in WebApiConfig.cs Please let me know the reason for calling twice.

Upvotes: 7

Views: 3699

Answers (1)

Pedro Drewanz
Pedro Drewanz

Reputation: 1292

If you register a filter in webapiconfig.cs it will run for every incoming request. If you decorate an action with a filter, it will run for that action. Since you registered the filter and decorated the action, it will run two times.

Upvotes: 4

Related Questions