asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 03:18:01  所属栏目: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.NET绑定指定media =屏幕的CSS bundle
 - asp.net core标签助手的高级用法TagHelper+Form
 - asp.net-mvc-3 – DropDownListFor Unobtrusive Validation
 - asp.net-mvc – 如何从mvc中的控制器中设置隐藏字段的值
 - asp.net – 在为app_offline.htm提供特定URL时,将http状态5
 - 谈谈ASP.NET Core中的ResponseCaching
 - 有什么好的参考或工具可用于将ASP转换为ASP.NET?
 - 实现ASP.NET多文件上传程序代码
 - 为什么私有事件处理程序在ASP.NET中不起作用
 - 如何为Asp.Net中的所有子文件夹注册HttpHandler?
 
推荐文章
            站长推荐
            - 你如何在ASP.NET中配置httpOnlyCookies?
 - [转]谈谈技术原则,技术学习方法,代码阅读及其它
 - 什么是使用aspnet_compiler.exe预编译ASP.NET项目
 - asp.net实现access数据库分页的方法
 - asp.net-mvc – ASP.NET MVC中的替代用户管理
 - asp.net – Lucene.Net和孵化状态
 - asp.net-mvc – 不应加载引用程序集以执行
 - asp.net – 我的HTML5的doctype是否必须在第一行
 - asp.net-core – “netcoreapp1.0”是一个不受支
 - asp.net中使用repeater和PageDataSource搭配实现
 
热点阅读
            