asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 05:40:06 所属栏目: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标签控件 – 不编码HTML
- 所有我使用IO的动作都是异步的?
- asp.net – Visual Studio 2010图表控件:使Y轴成为整数值,
- asp.net – SQL Server查询从ADO.NET运行速度比SSMS慢
- ASP.NET MVC3 RAZOR:文件上载给出文件计数为零
- 从asp.net mvc生成PDF文件
- asp.net-mvc – 为什么ASP.NET MVC 4与IList for editor不能
- Autofac和ASP.NET Web API ApiController
- ASP.NET设计网络硬盘之删除文件夹实现代码
- asp.net – 在fileupload中选择立即调用C#函数文件
推荐文章
站长推荐
- IIS ASP.NET WebApi在请求同一台服务器时死锁
- asp.net-mvc – 未在ELMAH中记录的错误
- 在ASP.net中使用NVP API时,PayPal SetExpressChe
- ASP.NET MVC3 RAZOR:文件上载给出文件计数为零
- asp.net-mvc – asp.net mvc – string或int的路
- asp.net – 测试Oracle存储过程的最简单的方法
- asp.net中MVC借助Iframe实现无刷新上传文件实例
- asp.net – 防止TextBox中的特殊字符
- asp.net – 哪里是.ASPXAUTH cookie
- asp.net-mvc – 如何正确识别vs2008版本级别?
热点阅读
