简体   繁体   English

网络核心:找不到类型或名称空间名称“ GlobalFilterCollection”

[英]Net Core: Type or namespace name 'GlobalFilterCollection' could not be found

I am migrating a project from .Net 4.6.2 into .Net Core 2.0. 我正在将一个项目从.Net 4.6.2迁移到.Net Core 2.0。 What is the replacement for GlobalFilterCollection in Net Core? Net Core中GlobalFilterCollection的替代品是什么?

The type or namespace name 'GlobalFilterCollection' could not be found (are you missing a using directive or an assembly reference?)    HPE.Kruta.Web.Core  


    public static void RegisterGlobalFilters(GlobalFilterCollection filters)

In order to do this, you would explicitly need to add the System.Web.Mvc.dll in your project. 为此,您将明确需要在项目中添加System.Web.Mvc.dll Follow these steps: 跟着这些步骤:

In your project, under Dependencies in your solution explorer, right click and choose Add Reference option. 在您的项目中,在解决方案资源管理器中的“ Dependencies下,右键单击并选择“ Add Reference选项。 Then under the Reference Manager window, click on Browse. 然后在“ Reference Manager窗口下,单击“浏览”。

Then navigate where your ASP .NET is installed. 然后导航您的ASP .NET的安装位置。 It should be here: 应该在这里:

Program files(x86) --> Microsoft ASP.NET --> ASP.NET MVC 4.6 --> Assemblies---> System.Web.Mvc.dll 程序文件(x86)-> Microsoft ASP.NET-> ASP.NET MVC 4.6->程序集---> System.Web.Mvc.dll

Include this file in your Assemblies in your project. 将此文件包含在项目的程序集中。 Once you include this .dll file, simply import using System.Web.Mvc; 包含此.dll文件后,只需using System.Web.Mvc;导入即可using System.Web.Mvc; and then you would be able to use GlobalFilterCollection filters in your project. 然后您将可以在项目中使用GlobalFilterCollection filters

EDIT : 编辑

In .NET CORE, the way your register your filters has changed. 在.NET CORE中,注册过滤器的方式已更改。 I will just show you a small example on how you can register a filter. 我将仅向您展示一个有关如何注册过滤器的小例子。

As per official documentation : 根据官方文件

You can register a filter globally (for all controllers and actions) by adding it to the MvcOptions.Filters collection in the ConfigureServices method in the Startup class 您可以通过将其添加到Startup类的ConfigureServices方法中的MvcOptions.Filters集合中来全局注册一个过滤器(针对所有控制器和操作)。

For example: If I want to use AuthorizeAttribute, I cannot add AuthorizeAttribute into MvcOptions.Filters . 例如:如果要使用AuthorizeAttribute,则无法将AuthorizeAttribute添加到MvcOptions.Filters I would need to create an AuthorizationPolicy and use AuthorizeFilter . 我需要创建一个AuthorizationPolicy并使用AuthorizeFilter

var authorizepolicy= new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .RequireRole("Admin", "SuperUser")
        .Build();

services.AddMvc(options =>
{
    options.Filters.Add(new AuthorizeFilter(authorizepolicy));
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到类型或命名空间名称“GlobalFilterCollection”(是否缺少 using 指令或程序集引用?) - The type or namespace name 'GlobalFilterCollection' could not be found (are you missing a using directive or an assembly reference?) Net Core:找不到类型或命名空间名称“RoleProvider” - Net Core: Type or namespace name 'RoleProvider' could not be found “ASP.NET Core 1.0 RC2中找不到”类型或命名空间名称“ - “The type or namespace name could not be found” in ASP.NET Core 1.0 RC2 无法构建.Net core 2.2项目? 找不到类型或名称空间名称“系统” - Cannot build .Net core 2.2 project? The type or namespace name 'System' could not be found 将 .Net Core 项目从 3.1 降级到 2.2 - 找不到类型或命名空间名称“IWebHostEnvironment” - Downgrade .Net Core project from 3.1 to 2.2 - The type or namespace name 'IWebHostEnvironment' could not be found 使用 .NET Core Fakes 和 VS 2019 Preview 6.9.0 Preview 2.0 找不到类型或命名空间名称 - The type or namespace name could not be found with .NET Core Fakes and VS 2019 Preview 6.9.0 Preview 2.0 ASP.NET 核心 - 错误 CS0246 找不到类型或命名空间名称“ApplicationUserRole&lt;&gt;” - ASP.NET Core - Error CS0246 The type or namespace name 'ApplicationUserRole<>' could not be found 在DNX Core 5.0中找不到类型或命名空间名称“RNGCryptoServiceProvider” - The type or namespace name 'RNGCryptoServiceProvider' could not be found in DNX Core 5.0 在.Net Core应用中找不到类型或名称空间“系统” - The type or namespace 'system' could not be found in .Net Core app 找不到类型或名称空间名称“” - The type or namespace name ' ' could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM