asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-05-22 21:21:18 所属栏目: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 – MVC3 Url.Action查询字符串生成
- ASP.NET MVC:将自定义属性放入选择列表中的选项标签
- asp.net-mvc – MVC2中的REQUIRED String属性的服务器端验证
- asp.net-mvc-3 – 如何使用复选框列制作MVC 3 Webgrid?
- 在ASP.NET MVC 3中可以使用甜甜圈缓存
- C# 中的委托和事件 [转载]
- asp.net-mvc – 如何在控制器中显示警报消息
- asp.net-mvc – 在EditorFor for child对象中使用时,MVC无法
- asp.net – FindControl()返回null
- asp.net核心 – ASP.NET核心中的基本身份验证
推荐文章
站长推荐
- ASP.NET Core 1 RC2 Web应用入门点
- asp.net-mvc-3 – asp.net mvc3请求线程亲和
- asp.net-mvc – 如何在asp.net mvc中提交下拉列表
- asp.net-mvc – 在ASP.NET MVC中检测中止的请求
- asp.net – 如何使用EntityFramework种子数据代码
- asp.net-mvc-3 – 处理DbContext后的问题
- asp.net – 在Web.config更改后程序集不可用
- asp.net – Firefox和Chrome之间的1像素线高差
- asp.net-mvc – MVC5:@ Html.TextBoxFor(或Edit
- asp.net-web-api – 将Application Insight与ASP
热点阅读
