How can I get the actionName in a ActionFilter?
-
05-07-2019 - |
Question
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;
}
Solution
string actionName = (string)filterContext.RouteData.Values["action"];
OTHER TIPS
FYI, as of RC1, you do it like this:
filterContext.ActionDescriptor.ActionName
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow