Comment obtenir le nom d'action dans un filtre ActionFilter & # 65311;
-
05-07-2019 - |
Question
c'est mon ancien 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;
}
La solution
string actionName = (string)filterContext.RouteData.Values["action"];
Autres conseils
Pour votre information, à partir de RC1, vous le faites comme suit:
filterContext.ActionDescriptor.ActionName
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow