public class IsLoginFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//获得Controller类型
Type t = filterContext.ActionDescriptor.ControllerDescriptor.ControllerType;
//获得方法名
string actionname = filterContext.RouteData.Values["action"].ToString();
//是否有该特性
bool b = isThatAttribute<UniteAttribute>(actionname, t);
base.OnActionExecuting(filterContext);
}
public bool isThatAttribute<T>(string actionname, Type t)
{
int length = t.GetMethod(actionname).GetCustomAttributes(typeof(T), true).Length;
return length > 0 ? true : false;
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
}
}
string controllername = filterContext.RouteData.Values["controller"].ToString();
string actionname = filterContext.RouteData.Values["action"].ToString();