asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 06:03:41 所属栏目:asp.Net 来源:互联网
导读:检查从为ASP.NET MVC2编写的 http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc的示例代码,我注意到他们可以通过访问filterContext.ActionDescriptor和filterContext.ActionDescriptor.ControllerDescripto
检查从为ASP.NET MVC2编写的 http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc的示例代码,我注意到他们可以通过访问filterContext.ActionDescriptor和filterContext.ActionDescriptor.ControllerDescriptor来检查自定义属性是否应用于当前操作或控制器: public class ExitHttpsIfNotRequiredAttribute : FilterAttribute,IAuthorizationFilter { public void OnAuthorization(AuthorizationContext filterContext) { // snip // abort if a [RequireHttps] attribute is applied to controller or action if(filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute),true).Length > 0) return; if(filterContext.ActionDescriptor.GetCustomAttributes(typeof(RequireHttpsAttribute),true).Length > 0) return; // snip } } 什么是ASP.NET MVC 1方法检查动作和控制器的自定义属性?在ASP.NET MVC 1中没有我可以告诉的filterContext.ActionDescriptor. 解决方法更好更可靠*方法:filterContext.ActionDescriptor.GetCustomAttributes( typeof(RequireHttpsAttribute),true).Count> 0 虽然这可能只是MVC 3.0. (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c#中分布方法和分部类
- 这是一个bug?浮动操作被视为整数
- asp.net-mvc – AJAX POST到MVC Controller显示302错误
- asp.net下经典数据库记录分页代码
- 如何在ASP.NET 5中添加一个TypeScript绝对类型的定义?
- asp.net-mvc – 我需要有关HandleError的更多信息
- asp.net-mvc – ASP.NET MVC中的Windows Live ID
- asp.net-mvc – 在我的ASP.NET MVC网站中缓存不能正常工作?
- asp.net – IIS Web Garden中的Singleton对象
- 来自ASP.NET MVC站点的“无效的JSON原语:alihack”错误
推荐文章
站长推荐
- asp.net – 在部分视图中强制使用没有Html.Begin
- 什么是在asp.net中301重定向更推荐的方法?
- asp.net – IE8 Win7 Facebook Connect问题
- asp.net-mvc-3 – MVC 3使用RenderPage更改视图中
- asp.net-mvc-3 – 在同一父视图上多次使用一个部
- ASP.NET Core中实现用户登录验证的最低配置示例代
- 如何在ASP.NET中的GridView中定义CellPadding
- asp.net-web-api – 从ASP.NET Web API ASP.NET
- ASP.NET标签控件 – 不编码HTML
- .net – 可以为空的枚举类型的奇怪行为
热点阅读