ActionFilter에서 ActionName을 어떻게 얻을 수 있습니까?
-
05-07-2019 - |
문제
이것은 나의 오래된 코드입니다
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;
}
해결책
string actionName = (string)filterContext.RouteData.Values["action"];
다른 팁
FYI, RC1 기준으로는 다음과 같이합니다.
filterContext.ActionDescriptor.ActionName
제휴하지 않습니다 StackOverflow