Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting action filters list from base Controller

In Short: Does any know a way from the base controller to get a list of actionFilters being applied to the current executing action?

The Long: I am using ASP.NET MVC 1.0 framework. I have a "RequireSSL" actionFilter that I've recreated for checking out, however, if someone leaves the checkout and goes back to the store I would like to forward them back to non-secure version of the site.

It would be helpful in the base controller (I am using a custom base controller that inherits from the default Controller) to find out what actionFilters are being applied to the current action.

I could include this into the global.asax.cs I guess, any guidance here would be appreciated.

Thanks

like image 903
Ethode Avatar asked Nov 28 '25 08:11

Ethode


1 Answers

You can create an ActionFilter and implement OnActionExecuting. From this Attribute you could redirect them.

public sealed class MyRedirectAttributeAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

        if (!filterContext.ActionDescriptor.IsDefined(typeof(RequireSSLAttribute), true))
        {
            filterContext.HttpContext.Response.Redirect("~/Controller/Action");
        }

        base.OnActionExecuting(filterContext);
    }
}true
like image 161
Thad Avatar answered Nov 29 '25 22:11

Thad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!