Why is OnAuthorization called twice in my custom AuthorizationFilterAttribute?

白昼怎懂夜的黑 提交于 2019-12-05 10:33:52

The problem was with Ninject.Web.WebApi. For some reason it was registering the filter twice. Updating the package to latest (v 3.2.1) fixed the issue.

I had registered the AuthorizeAttribute in the WebAPIconfig.cs:

public static void Register(HttpConfiguration config)
{
   config.Filters.Add(new Global.Security.MyAuthorizeAttribute());

In addition I had decorated the method with the Attribute.

[MyAuthorize]
public IHttpActionResult Get(string name)

This caused the public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) method to be called twice.

The solution is either set one up globally (as a config filter) or add attributes to methods individually.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!