Fromeast
Fromeast

Reputation: 73

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;
    }

Upvotes: 7

Views: 7538

Answers (2)

Tim Scott
Tim Scott

Reputation: 15205

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

filterContext.ActionDescriptor.ActionName

Upvotes: 32

Craig Stuntz
Craig Stuntz

Reputation: 126547

string actionName = (string)filterContext.RouteData.Values["action"];

Upvotes: 12

Related Questions