如何使用MVC 6,asp.net 5注册全局筛选器 [英] How to register a global filter with mvc 6, asp.net 5
问题描述
我想注册一个简单的MVC应用程序的过滤器。我还没有真正写任何东西的基本过滤器来测试之外。我使用的是2015年VS RC和我转到新项目创建的初始应用程序 - > Asp.net Web应用程序 - >网络API。我遇到的问题是,我无法找到一个方法来注册全局过滤器。
从早期版本的MVC我看到 GlobalFilters.Filters
,但是当我尝试使用新的框架中它告诉我,GlobalFilters无法找到。在previous版本中,它住在System.Web.MVC,但我再也看不到,在我的引用,我似乎无法在任何地方找到它。
这看起来应该是很简单的,但到目前为止,我还没有找到一个方法来做到这一点。
下面是我的project.json
{
根目录:wwwroot的
版本:1.0.0- *, 依赖:{
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
}, 命令:{
网络:Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls的http://本地主机:5000
}, 构架: {
dnx451:{
frameworkAssemblies:{
}
},
dnxcore50:{}
}, 排除:[
wwwroot的
node_modules
bower_components
]
publishExclude:[
node_modules
bower_components
**。xproj
**。用户,
**。vspscc
]
}
你如何能做到这MVC中6例
公共无效ConfigureServices(IServiceCollection服务)
{
services.AddMvc();
services.ConfigureMvc(选项=>
{
options.Filters.Add(新YouGlobalActionFilter());
}
}
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"
]
}
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());
}
}
这篇关于如何使用MVC 6,asp.net 5注册全局筛选器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!