查看http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc为 ASP.NET MVC2 编写的示例代码,我注意到他们可以检查自定义属性是否为通过分别访问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
,我无法判断。