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
、私が言えることはありません。