asp.net-web-api - Visual Studio 2015 中的 FilterConfig

标签 asp.net-web-api visual-studio-2015 asp.net-core-mvc

我正在尝试将我的 asp.net mvc Web api 项目迁移到 Visual Studio 2015 预览版。

我没有找到在 Visual Studio 2015 上采用 FilterConfig.cs 代码的方法,因为 2015 版本不支持 global.asax、web.config。

所以我可以把我的过滤器配置、区域配置放在哪里。

最佳答案

您需要在 StartUp 类的ConfigureServices 方法内注册过滤器:

    public void ConfigureServices(IServiceCollection services)
    {
        // Add MVC services to the services container.
        services.AddMvc().Configure<MvcOptions>(options =>
        {
            options.Filters.Add(typeof (MyGlobalFilterAttribute));
        });
    }

关于asp.net-web-api - Visual Studio 2015 中的 FilterConfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060640/

相关文章:

c# - Web API 中的 MVC-6 与 MVC-5 承载身份验证

C#.net Web 请求在调用 Web API 时无法获取 404 自定义错误消息,但 postman 却可以

asp.net-mvc - OnExceptionAsync 与 OnException 之间的 ExceptionFilter 区别

c# - 当从另一个项目内部提供 api 时,如何在 Swashbuckle/Swaggerwork 中创建 url 路径?

c# - Asp.net Core 2.1 日志记录

c# - 数据库播种仅适用于一个模型,不适用于第二个模型

asp.net-web-api - 如何访问 Web API Controller 中的 Identity UserManager 来发送电子邮件

msbuild - 有没有一种简单的方法可以从 Visual Studio 2015 项目自动创建 NuGet 包?

c++ - 在 Visual Studio 中为单个解决方案编译和使用多个项目

vb.net - 升级到 Office 2016 引用错误 : Microsoft. Office.Interop.Excel