Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the actionName in a ActionFilter?

this is my old code


    protected override bool OnPreAction(string actionName, System.Reflection.MethodInfo methodInfo)
    {
        if ("|Register|RegisterPage|Login|LoginPage|Logout|Service".ToLower().Contains(actionName.ToLower()))
        {
            return base.OnPreAction(actionName, methodInfo);
        }

        Customer = CustomerHelper.GetCustomer();

        if (Customer.IsSeccessedLogin())
        {
            return base.OnPreAction(actionName, methodInfo);
        }

        Response.Redirect("Login.html");
        return false;
    }
like image 887
Fromeast Avatar asked Oct 29 '08 08:10

Fromeast


People also ask

How do you implement an action filter?

You can create a custom action filter in two ways, first, by implementing the IActionFilter interface and the FilterAttribute class. Second, by deriving the ActionFilterAttribute abstract class.

What are the action filters?

Action filters contain logic that is executed before and after a controller action executes. You can use an action filter, for instance, to modify the view data that a controller action returns. Result filters contain logic that is executed before and after a view result is executed.


1 Answers

FYI, as of RC1, you do it like this:

filterContext.ActionDescriptor.ActionName
like image 93
Tim Scott Avatar answered Oct 06 '22 15:10

Tim Scott