public class GlobalActionFilter : ActionFilterAttribute
{
private string _requestId;
public override void OnActionExecuting(HttpActionContext actionContext)
{
 base.OnActionExecuting(actionContext);

//方法1.

var gaf=actionContext.ActionDescriptor.GetCustomAttributes<GlobalAuthorizationFilter>().FirstOrDefault();

string methodName1 = actionContext.ActionDescriptor.ActionName;
//var ad=actionContext.ActionDescriptor.MethodInfo; //MethodInfo调试可以看到,但是代码点不出来

//方法2:反射
var methodActionDescriptorProperty = actionContext.Request.Properties["MS_HttpActionDescriptor"] as ReflectedHttpActionDescriptor;
if (methodActionDescriptorProperty != null)
{
  var methodInfo = methodActionDescriptorProperty.MethodInfo; //获取方法详情
  string methodName = methodInfo.Name; //方法名
  var methodCustomAttributes = methodInfo.GetCustomAttributes(true).ToList(); //获得所有自定义的attributes标记 var authAttribute = methodCustomAttributes.FirstOrDefault(ee => ee is GlobalAuthorizationFilter); //查找是否有特定的attribute标记
if (authAttribute != null)
{
var gf = authAttribute as GlobalAuthorizationFilter; //转换为特定的attribute
bool isNeedLogin = gf.IsNeedLogin; //拿到特定标记的字段 }
} }

From:http://www.cnblogs.com/xuejianxiyang/p/6208406.html

webapi filter过滤器中获得请求的方法详情(方法名,Attributes)的更多相关文章

  1. web过滤器中获取请求的参数(content-type:multipart/form-data)

    1.前言: 1.1 在使用springMVC中,需要在过滤器中获取请求中的参数token,根据token判断请求是否合法: 1.2 通过requst.getParameter(key)方法获得参数值; ...

  2. 子类重载父类的方法“parent::方法名”转于 恩聪PHP学习教程

    在PHP中不能定义重名的函数,也包括不能再同一个类中定义重名的方法,所以也就没有方法重载.单在子类中可以定义和父类重名的方法,因为父类的方法已经在子类中存在,这样在子类中就可以把从父类中继承过来的方法 ...

  3. 子类重载父类的方法“parent:方法名”

    在PHP中不能定义重名的函数,也包括不能再同一个类中定义重名的方法,所以也就没有方法重载.单在子类中可以定义和父类重名的方法,因为父类的方法已经在子类中存在,这样在子类中就可以把从父类中继承过来的方法 ...

  4. java中Filter过滤器处理中文乱码的方法

    注意问题:在学习用selvert的过滤器filter处理中文乱码时,在filter配置初始化时用了utf-8处理中文乱码,而在提交的jsp页面中却用了gbk.虽然两种都可以出来中文乱码,但是却造成了处 ...

  5. .net Core在过滤器中获取 系统接口方法(以IMemoryCache 为例) 及HttpContext 获取系统接口

    public   Class  SysActionAttribute :Attribute, IActionFilter      //  Attribute  用于控制器中 特性控制,当在控制器或控 ...

  6. 转:.NET获取当前方法名或调用此方法的方法名

    Introduction Before .NET, we were always looking for a way to log current method name in a log file ...

  7. C# 外界调用方法是 方法名是string类型的解决方法

  8. 【Servlet】Java Serlvet Filter 过滤器

    Filter的设计思想Filter是一种AOP(aspect-oriented programming)的设计思想 : 面向切面编程.用于的请求和响应都会走 使用filter的登录案例我们通过一张图片 ...

  9. 02 Filter过滤器

    Filter 一.Filter过滤器 Filter过滤器它是JavaWeb的三大组件之一.三大组件分别是:Servlet程序.Listener监听器.Filter过滤器 Filter过滤器是JavaE ...

随机推荐

  1. ABP理论学习之通知系统

    返回总目录 本篇目录 介绍 订阅通知 发布通知 用户通知管理者 实时通知 通知存储 通知定义 介绍 通知(Notification)用于告知用户系统中的特定事件.ABP提供了基于实时通知基础设施的发布 ...

  2. mysql定义和调用存储过程

    /*定义delimiter为 // */ delimiter // CREATE procedure sp_add3(a int, b int,out c int) begin set c=a+ b; ...

  3. linux 使用fdisk分区扩容

    标签:fdisk分区 概述 我们管理的服务器可能会随着业务量的不断增长造成磁盘空间不足的情况,在这个时候我们就需要增加磁盘空间,本章主要介绍如何使用fdisk分区工具创建磁盘分区和挂载分区,介绍两种情 ...

  4. [ASP.NET MVC 小牛之路]17 - 捆绑(Bundle)

    本文介绍 MVC 4 提供的一个新特性:捆绑(Bundle),一个在  View 和 Layout 中用于组织优化浏览器请求的 CSS 和 JavaScript 文件的技术. 本文目录 了解VS默认加 ...

  5. [翻译] AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)

    原文在http://rerun.me/2014/10/06/akka-notes-actorsystem-in-progress/ 像我们前面看到的,我们可以用ActorSystem的actorof方 ...

  6. JavaScript学习笔记之string

    字符串定义: 1,var myString=“内容”:or var myString=‘内容’ 2,var myString= new String(“内容”)           ---〉创建对象, ...

  7. Entity Framework Code First执行SQL语句、视图及存储过程

    1.Entity Framework Code First查询视图 Entity Framework Code First目前还没有特别针对View操作的方法,但对于可更新的视图,可以采用与Table ...

  8. js self = this的解释

    Demo 1: function Person(){ this.name = 'hjzgg'; this.age = 24; this.show = function(){ alert(name + ...

  9. MySQL学习笔记十五:优化(2)

    一.数据库性能评测关键指标 1.IOPS:每秒处理的IO请求次数,这跟磁盘硬件相关,DBA不能左右,但推荐使用SSD. 2.QPS:每秒查询次数,可以使用show status或mysqladmin ...

  10. iOS开发之版本控制(SVN)

    版本控制对于团队合作显得尤为重要,那么如何在iOS开发中进行版本控制呢?在今天的博客中将会介绍如何在MAC下配置SVN服务器,如何导入我们的工程,如何在Xcode中进行工程的checkOut和Comm ...