asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 05:49:13 所属栏目: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. (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net 将一个图片以二进制值的形式存入Xml文件中的实例代
- ASP.NET:预编译文件的文件名生成规则
- ASP.NET MVC与Webforms:替换WebForms控件
- asp.net – Silverlight初始化错误2110 Internet Explorer
- asp.net – 获得“System.Web.Mvc.Html.MvcForm”一页
- 只需发布已修改的控制器,模型和ASP.NET MVC项目的某些部分
- asp.net – Orchard CMS和Sitefinity CMS
- asp.net-mvc-4 – 在哪里可以找到WebMatrix.WebData.WebSec
- 从代码隐藏调用ASP.NET Web API
- entity-framework – 如果EF 5,如何定义自定义命名约定
推荐文章
站长推荐
- WCF服务与ASP.NET Web Api
- asp.net-mvc – 文件上传MVC
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-optio
- 有没有办法从ASP.NET访问IIS内核缓存?
- asp.net – WebBrowsable vs个性化Web部件
- asp.net – 让Visual Studios使用子域名?
- 如何刷新#include文件 – 它们在IIS7 / ASP.NET上
- asp.net – 我如何使用AJAX来确定用户的会话是否
- asp.net – 如何在MVC 3中设置图表系列颜色?
- asp.net-core – ASP.Net 5类库中的EntityFramew
热点阅读