asp.net-mvc – 在ASP.NET MVC中获取当前操作/控制器的自定义属性列表
发布时间:2020-12-05 04:07:24 所属栏目: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. (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 通过Linux上的Azure应用服务强制从ASP.NET Core返回Connect
- 在asp.net中使用eval(“”)
- asp.net – Oracle.ManagedDataAccess:TNS:无法解析指定的
- 如何处理在MVC视图中应用程序启动和传输和显示错误发生的AS
- asp.net – 如何正确地大写希腊字在.NET?
- asp.net-mvc – 使用输出缓存和其他动作过滤器
- asp.net-mvc-3 – 局部视图中的RenderSection
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-options
- asp.net – WebFormsMVP的缺点?
- .net – RESTful WCF的裸最低配置
推荐文章
站长推荐
- asp.net-mvc – 如何成功配置Common.Logging?
- ASP.NET中的超链接控件和链接控件有什么区别?
- 单元测试 – 如何在ASP MVC 5(Microsoft.AspNet.
- asp.net-mvc – 在asp.net mvc 3剃刀中识别html助
- asp.net – 干净的方式来防止输入按钮提交表单
- asp.net-web-api – WebAPI中的长时间运行任务
- asp.net-mvc – ASP.NET MVC查看引擎解析顺序
- asp.net-mvc – 带vNext的MVC 6:我们还需要Glob
- asp.net – 选择框更改事件中的setTimeout
- asp.net – Web Forms MVP项目有哪些好的资源?
热点阅读