asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属
发布时间:2020-12-15 20:27:37 所属栏目:asp.Net 来源:网络整理
导读:检查从为ASP.NET MVC2编写的 http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc的示例代码,我注意到他们可以通过访问filterContext.ActionDescriptor和filterContext.ActionDescriptor.ControllerDescriptor来检查自定义
检查从为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-3 – 可以添加到显示/ EditorTemplates ASP.NE
- asp.net-mvc-4 – ASP.NET Web API架构建议/反馈
- asp.net – 正则表达式验证器不验证空文本框
- asp.net-mvc – window.location.href发送多个参数asp.net
- ASP.NET MVC图像上传存储位置(db vs filesystem)
- asp.net 多文件上传,兼容IE6/7/8,提供完整代码下载
- Asp.net中UpdatePanel内FileUpload的正确使用方法
- asp.net-mvc – 使用ASP.NET MVC的Piranha CMS路由问题
- 从asp页面调用C#函数
- asp.net – 调用SqlMembershipProvider GetUser的无效Cast
推荐文章
站长推荐
- asp.net – 如何获取“发布网站”命令为我的Visu
- 突出显示ASP.Net菜单中的选定选项卡
- iis – 我应该为我的生产服务器使用processModel
- asp.net – 这是一个RESTFUL MVC Web服务吗?
- asp.net-mvc – MVC4上的服务堆栈
- asp.net – 在SQL SERVER 2005上启用CLR是否存在
- asp.net-mvc – 如何在Ajax.BeginForm中使用Html
- ASP.NET网站 – > WCF服务 – > WCF服务,一路冒充
- asp.net-web-api – 如何将OData过滤器转换为LIN
- asp.net-mvc-4 – 使用剃刀循环模型
热点阅读