I'm trying to register a filter in a simple mvc application. I haven't even really written anything yet outside of the basic filter to test with. I'm using VS 2015 RC and I created the initial application by going to new project -> Asp.net Web Application -> Web API. The problem I'm having is that I can't find a way to register the filter globally.
From earlier versions of MVC I see the GlobalFilters.Filters
, but when I try to use that in the new framework it tells me that GlobalFilters can't be found. In previous versions it lived in System.Web.MVC, but I no longer see that in my references, and I can't seem to find it anywhere.
This seems like it should be very simple but so far I haven't found a way to do it.
Here's my project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
}
},
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
With Beta 8 it is now done via AddMvc as follows:
services.AddMvc(options =>
{
options.Filters.Add(new YouGlobalActionFilter());
});
Example of how you can do it in MVC 6
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.ConfigureMvc(options =>
{
options.Filters.Add(new YouGlobalActionFilter());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With