2008-10-29 209 views
6

這是我的舊代碼我怎樣才能獲得actionName在ActionFilter


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

高興你正在尋找更好的方法。那是......有點可怕:) – 2008-10-29 13:30:15

回答

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

僅供參考,如RC1的,你做這樣的:

filterContext.ActionDescriptor.ActionName