asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 04:10:56 所属栏目: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. (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如何编辑表格数据(ASP MVC)
- 如何在ASP.NET Web应用程序中打开一个SectionGroup?
- asp.net-mvc – Visual Studio 2010 Full和ASP.NET MVC 2.0
- asp.net-mvc – MVC DB首先修复显示名称
- asp.net – 实体框架CTP5,代码优先.可选的导航属性
- 使用ASP.NET AJAX Control Toolkit设置焦点
- ASP.Net WebAPI与Ajax进行跨域数据交互时Cookies数据的传递
- asp.net ajax实现无刷新验证码
- asp.net-mvc – 不应加载引用程序集以执行
- asp.net – Web Forms MVP项目有哪些好的资源?
推荐文章
站长推荐
- 我如何让Fiddler捕获我的MVC应用程序向我的ASP.N
- 集成ASP.NET Webforms,WebAPI和AngularJS
- asp.net-mvc – Windows 8 VS2012 IISExpress Wi
- asp.net-mvc – 如何从剃刀视图访问My.Resources
- ASP.NET JSON字符串与实体类的互转换示例代码
- 如何在ASP.NET MVC中配置3个级别的URL?
- asp.net汉字转拼音和获取汉字首字母的代码
- ASP.NET中上传并读取Excel文件数据示例
- ASP.NET MVC编辑器模板和Html.EditorFor(…) –
- 如何为ASP.NET身份设置密码规则?
热点阅读