Overriding the global action filter

Several pages on my site should use SSL, so I added [RequireHttps]to the respective controllers. However, I still want most of my pages to always use non-SSL, so I successfully used the code I found on SO to create my own filter [DoNotUseHttps].

To simplify the task, I would like to enable this filter without SSL by default, so I added it to the global filters that are installed in the Global.asax file. However, it looks like I created an infinite loop with each redirecting the filter to another.

Which leads me to my question ... is there anything I can add to my global filter to determine if it [RequireHttps]has already been applied to the controller?

+5
source share
1 answer

Of course, you can interrogate anything about actions and controllers. Check RequireHttpsAttribute:

public override void OnActionExecuted(ActionExecutedContext filterContext)
{
    base.OnActionExecuted(filterContext);

    bool requireHttps = filterContext.ActionDescriptor.ControllerDescriptor
        .GetCustomAttributes(typeof(RequireHttpsAttribute), true).Length > 0
 }
+5
source

All Articles