WebAPI 之问题记录

这篇博客是博主的第一篇博客,主要用于webapi学习过程中的问题记录

问题1:  重写OnAuthorization权限验证时,遇到AllowAnonymousAttribute特性不起作用的问题

public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
    //遇到AllowAnonymousAttribute这个特性,权限验证
    if (((ReflectedHttpActionDescriptor)actionContext.ActionDescriptor)
         .MethodInfo.IsDefined(typeof(AllowAnonymousAttribute), true)
         || actionContext.ActionDescriptor.ControllerDescriptor
         .ControllerType.IsDefined(typeof(AllowAnonymousAttribute), true))
    {
        return;
    }
    //验证权限代码、、、
    
}

 

posted @ 2019-09-05 14:43  uopen  阅读(270)  评论(0)    收藏  举报