webapi filter过滤器中获得请求的方法详情(方法名,Attributes)
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)的更多相关文章
- web过滤器中获取请求的参数(content-type:multipart/form-data)
1.前言: 1.1 在使用springMVC中,需要在过滤器中获取请求中的参数token,根据token判断请求是否合法: 1.2 通过requst.getParameter(key)方法获得参数值; ...
- 子类重载父类的方法“parent::方法名”转于 恩聪PHP学习教程
在PHP中不能定义重名的函数,也包括不能再同一个类中定义重名的方法,所以也就没有方法重载.单在子类中可以定义和父类重名的方法,因为父类的方法已经在子类中存在,这样在子类中就可以把从父类中继承过来的方法 ...
- 子类重载父类的方法“parent:方法名”
在PHP中不能定义重名的函数,也包括不能再同一个类中定义重名的方法,所以也就没有方法重载.单在子类中可以定义和父类重名的方法,因为父类的方法已经在子类中存在,这样在子类中就可以把从父类中继承过来的方法 ...
- java中Filter过滤器处理中文乱码的方法
注意问题:在学习用selvert的过滤器filter处理中文乱码时,在filter配置初始化时用了utf-8处理中文乱码,而在提交的jsp页面中却用了gbk.虽然两种都可以出来中文乱码,但是却造成了处 ...
- .net Core在过滤器中获取 系统接口方法(以IMemoryCache 为例) 及HttpContext 获取系统接口
public Class SysActionAttribute :Attribute, IActionFilter // Attribute 用于控制器中 特性控制,当在控制器或控 ...
- 转:.NET获取当前方法名或调用此方法的方法名
Introduction Before .NET, we were always looking for a way to log current method name in a log file ...
- C# 外界调用方法是 方法名是string类型的解决方法
- 【Servlet】Java Serlvet Filter 过滤器
Filter的设计思想Filter是一种AOP(aspect-oriented programming)的设计思想 : 面向切面编程.用于的请求和响应都会走 使用filter的登录案例我们通过一张图片 ...
- 02 Filter过滤器
Filter 一.Filter过滤器 Filter过滤器它是JavaWeb的三大组件之一.三大组件分别是:Servlet程序.Listener监听器.Filter过滤器 Filter过滤器是JavaE ...
随机推荐
- Java NIO3:通道和文件通道
通道是什么 通道式(Channel)是java.nio的第二个主要创新.通道既不是一个扩展也不是一项增强,而是全新的.极好的Java I/O示例,提供与I/O服务的直接连接.Channel用于在字节缓 ...
- 备忘-Android ViewPager 与Gallery滑动冲突解决方法
解决方法,重新定义gallery,禁止触发pager的触摸事件 1 public class UserGallery extends Gallery implements OnGestureListe ...
- 为jQuery添加Webkit的触摸方法支持
前些日子收到邮件,之前兼职的一个项目被转给了其他人,跟进的人来问我相关代码的版权问题. 我就呵呵了. 这段代码是我在做13年一份兼职的时候无聊加上去的,为jQuery添加触摸事件的支持.因为做得有点无 ...
- WCF wsHttpBinding之Transport security Mode, clientCredentialType=”Basic”
原创地址:http://www.cnblogs.com/jfzhu/p/4071342.html 转载请注明出处 如何在WCF中使用Transport Security Mode,以及如何创建证书,请 ...
- Step by step Dynamics CRM 2013安装
原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处 SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...
- VS2013的 Browser Link 引起的问题
环境:vs2013 问题:在调用一个WebApi的时候出现了错误: 于是我用Fiddler 4直接调用这个WebApi,状态码是200(正常的),JSon里却提示在位置9409处文本非法, 以Text ...
- hibernate注解方法使用总结(转)
原博文地址:http://blog.sina.com.cn/s/blog_935ebb670101dnre.html 1.类级别注解 @Entity 映射实体类 @Table 映射数据库 ...
- $watch $apply and $evalAsync vs $timeout
$watch $scope对象上的$watch方法会给Angular事件循环内的每个$digest调用装配一个脏值检查. 如果在表达式上检测到变化, Angular总是会返回$digest循环. $w ...
- DAC Usage3:Monitor Data-tier Applications
If you deploy a DAC to a managed instance of the Database Engine, information about the deployed DAC ...
- LINQ系列:Linq to Object生成操作符
生成操作符从现有序列值中创建新的序列. 1. Empty Empty操作符返回一个指定类型的空集. 1>. 原型定义 public static IEnumerable<TResult& ...