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;
    }
    //验证权限代码、、、
    
}
原文地址:https://www.cnblogs.com/uopen/p/11465910.html