System.Web.Mvc.ActionDescriptor
has 方法IsDefined
有助于确定是否为此成员定义了指定属性类型的一个或多个实例。
Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext
没有这个方法。
我如何检查AllowAnonymousAttribute
使用ActionExecutingContext
?
ActionExecutingContext
给你ActionDescriptor
。从那里,您可以检查AllowAnonymousAttribute
.
class MyFilter: IAsyncActionFilter
{
public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var isAnonymous = context.ActionDescriptor.EndpointMetadata.OfType<AllowAnonymousAttribute>().Any();
// ...
return next();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句