asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 05:21:29 所属栏目: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 – Dropzone没有绑定到模型
- asp.net-mvc – 使用Asp.net MVC 4中的OutputCacheAttribut
- asp.net-core – 如何使用ASP.NET注册OData 5
- 在ASP.NET中拒绝用户时,’CustomIdentity’上的Serializati
- asp.net – 如何查看Chrome开发者工具中发布到表单的数据大
- asp.net-web-api – Web API / MVC 6中的安全JSON Web令牌
- asp.net-mvc – 在MVC Controller中访问GET参数
- 从Asp.Net MVC 6 API返回JSON错误
- asp.net-mvc – 图像URL中的符号MVC导致一个潜在危险的Requ
- asp.net-mvc-3 – 剃刀引擎 – 如何根据不同的条件渲染不同
推荐文章
站长推荐
- asp.net中利用Jquery+Ajax+Json实现无刷新分页的
- 如何在ASP.NET页面上使用框架?
- asp.net – Visual Studio – 为什么.ASPX文件比
- 增加ASP.NET站点的executionTimeout和maxRequest
- asp.net-mvc – 为什么我在带有godaddy服务器的M
- asp.net读取excel文件的三种方法示例
- asp.net – 从多个Web.config文件访问appSetting
- ASP.NET(C#)应用程序配置文件app.config/web.con
- asp.net类序列化生成xml文件实例详解
- asp.net-mvc – ASP.NET MVC Beta 1:DefaultMod
热点阅读
