asp.net-mvc – ASP.NET MVC检查Controller或Action中的自定义属性
发布时间:2020-09-01 13:23:02 所属栏目:asp.Net 来源:互联网
导读:请考虑以下代码: public class MyAttribute : Attribute { }[MyAttribute]public class MyControlller : Controller{ //...} 现在我有一个全局动作过滤器,它获取一个ActionExecutingContext对象. 我的问题是,在这里,我如何检查所请求的Controller是否已使
请考虑以下代码: public class MyAttribute : Attribute { } [MyAttribute] public class MyControlller : Controller { //... } 现在我有一个全局动作过滤器,它获取一个ActionExecutingContext对象. 我的问题是,在这里,我如何检查所请求的Controller是否已使用我的自定义属性进行装饰. 解决方法尝试actionExecutingContextInstance.Controller.GetType().GetCustomAttributes(typeof(MyAttribute),false).Length > 0) 要么 actionExecutingContextInstance.ActionDescriptor.GetCustomAttributes(typeof(MyAttribute),false).Length > 0) (编辑:十堰站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附
- asp.net-mvc – ASP.NET MVC:部分知道它是否是从另一个页面
- asp.net – 如何在南希显示我的404页面?
- asp.net – 多个用户控件和JavaScript
- asp.net – CalendarExtender定位问题
- .net – RESTful WCF的裸最低配置
- asp.net – 允许服务器/ usercontrol上的任何属性/属性
- asp.net – 将ViewState移出页面?
- asp.net-mvc – asp.net mvc – string或int的路由(即/ typ
- ASP.NET linkbutton两次提高onBeforeUnload事件
推荐文章
站长推荐
- asp.net – 错误:数据绑定方法(如Eval(),XPath(
- asp.net-mvc – LabelFor和TextBoxFor不生成相同
- .net – ELMAH对企业库异常处理块
- asp.net – OutOfMemoryException当发送大文件50
- IIS ASP.NET WebApi在请求同一台服务器时死锁
- 如何排序. .NET中的resx(资源文件)
- asp.net – VirtualPathUtility.ToAbsolute()VS.
- ASP.NET core Web中使用appsettings.json配置文件
- asp.net-mvc – 如何使用selenium进行ASP.NET MV
- asp.net-mvc-3 – MVC3正确的方式来改变每个请求
热点阅读