asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 03:38: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 – 在SQL Server中将日期转换为刻度
- asp.net – 无法在UpdatePanel中下载文件
- asp.net-mvc – 如何继承ASP.NET MVC控制器并仅更改视图?
- asp.net-mvc-3 – 为什么@ Html.Label()删除一些字符
- asp.net – 测试Oracle存储过程的最简单的方法
- asp.net – Application_error函数间歇性捕获“文件不存在”
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-options
- asp.net – 我可以重新发布或携带POST数据(如果是这样,我可
- ASP.NET中操作SQL数据库(连接字符串的配置及获取)
- 从asp.net mvc生成PDF文件
推荐文章
站长推荐
- asp.net-mvc-4 – MVC4捆绑GZIP和头文件
- 设置ASP.NET页面不被缓存(客户端/服务器端取消缓
- asp.net – 更改事件和IE8的jQuery问题
- asp.net-mvc – Azure git部署 – 第二个程序集中
- ASP.NET Core中调整HTTP请求大小的几种方法详解
- asp.net-mvc – 在没有模型的情况下手动将验证添
- ASP.NET页面验证
- asp.net – 从多个Web.config文件访问appSetting
- asp.net-mvc – asp.net mvc – string或int的路
- asp.net – 什么是system.globalization它和本地
热点阅读
