Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 468
user145610 Avatar asked Jan 28 '14 13:01

user145610


1 Answers

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.

like image 151
Pedro Drewanz Avatar answered Oct 03 '22 22:10

Pedro Drewanz