Adding controller-as-filter support

If the controller implements IFilter, it will be added to the filters
collection.

It's hardcoded to be 'first' as it was in MVC.
This commit is contained in:
Ryan Nowak 2014-04-30 16:38:56 -07:00
parent 67b33868a3
commit ae4e3bc61d
2 changed files with 9 additions and 0 deletions

View File

@ -88,6 +88,14 @@ namespace Microsoft.AspNet.Mvc.Filters
ApplyFilterToContainer(filterItem.Filter, filterFactory);
}
var controllerFilter = context.ActionContext.Controller as IFilter;
if (controllerFilter != null)
{
// If the controller implements a filter, we want it to be the first to run.
var descriptor = new FilterDescriptor(controllerFilter, FilterScope.Action);
context.Result.Insert(0, new FilterItem(descriptor, controllerFilter));
}
}
private void InsertControllerAsFilter(FilterProviderContext context, IFilter controllerFilter)

View File

@ -110,6 +110,7 @@
<Compile Include="Filters\ResultExecutionDelegate.cs" />
<Compile Include="Filters\ResultFilterAttribute.cs" />
<Compile Include="Filters\ServiceFilterAttribute.cs" />
<Compile Include="ControllerFilterProvider.cs" />
<Compile Include="FormContext.cs" />
<Compile Include="HttpDeleteAttribute.cs" />
<Compile Include="HttpGetAttribute.cs" />