Using IOverrideFilter to override custom ActionFilters

后端 未结 1 575
予麋鹿
予麋鹿 2021-02-16 00:18

I want to use IOverrideFilter interface to override my custom global filter but it is simply not working! Code looks like to be as follow:

public se         


        
相关标签:
1条回答
  • 2021-02-16 00:28

    The msdn info is not entirely clear about it but IOverrideFilter.FiltersToOverride must be exactly one of the following:

    • IActionFilter
    • IAuthorizationFilter
    • IAuthenticationFilter
    • IExceptionFilter

    Basically, you cannot override specific filters, you can only override all the filters of one of the categories above. Have a look a the ProcessOverrideFilters method in the source code.

    So, let's say that your ITest filter is of type IActionFilter, then your override will be (The same logic would apply for any other filter category):

    public Type FiltersToOverride
    {
        get { return typeof(IActionFilter); }
    }
    

    You could also use the predefined OverrideActionFilters (and similar predefined override attributes for other filter categories).

    For a more fine-grained override, you might need to develop specific solutions like this one or write your own filter provider as in this very nice article

    0 讨论(0)
提交回复
热议问题