2015-08-26 22 views
1

我創建了一個名爲[ValidateUrlAttribute]操作篩選,我想用這個動作過濾器除了在我的class.I一些方法嘗試這以後的事,但它不工作如何僅爲一種方法禁用Actionfilter?

public class ActionExemptionsAttribute : ActionFilterAttribute 
    { 
    public string Exemption { get; set; } 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     if (filterContext.RouteData.GetRequiredString("action") == Exemption) 
      return; 

     base.OnActionExecuting(filterContext); 
    } 

} 
+0

介意分享一些代碼?而你試過的什麼都不起作用? – shashwat

+1

我想你可以在這裏找到你需要的東西:http://stackoverflow.com/questions/9953760/how-to-disable-a-global-filter-in-asp-net-mvc-selectively – Charmander

+0

[ActionExemptions(Exemption =「GetUserDetailsForCreatePassword」)]在控制器我試過這樣但它不起作用 – Vinoth

回答

2

您應該引入自定義屬性(例如SkipActionExemptionsAttribute),您可以使用它來對想要跳過檢查URL的動作進行貶低

在您的ActionExemptionsAttribute中,檢查動作是否使用Skip屬性進行了裝飾。

actionContext 
     .ActionDescriptor 
     .GetCustomAttributes<SkipActionExemptionsAttribute>() 
     .Any() 
相關問題