我有一个Controller,其中某些方法具有授权属性,而某些方法具有AllowAnonymous 所以,我想在调用时检查方法是Authorize或AllowAnonymous
这是我的方法名称为
的控制器[AllowAnonymouse]
Public ActionResult Login(){}
所以在不同的类中,我想检查此方法是Authorize还是AllowAnonymous
答案 0 :(得分:1)
string actionName = ViewContext.RouteData.Values["Action"]
MethodInfo method = type.GetMethod(actionName);
var attribute = method.GetCustomAttributes(typeof(DisplayNameAttribute), false);
if (attribute.Length > 0)
actionName = ((DisplayNameAttribute)attribute[0]).DisplayName;
else
actionName = type.Name;
检查此链接: