【问题标题】:.NET Core - IAuthorizationFilter not found.NET Core - 未找到 IAuthorizationFilter
【发布时间】:2020-09-17 15:40:25
【问题描述】:

我尝试使用 .NET Core 3.1 创建过滤器

由于一些奇怪的原因,很多东西都找不到

找不到类型或命名空间名称“FilterAttribute”(您是否缺少 using 指令或程序集引用?)

首先,找不到System.Web.Mvc,所以我卸载了,重新安装了microsoft apsnet mvc包

但我仍然遇到同样的问题

using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc.Filters;

namespace MyApp.Filters
{
    public class CustomAuthorizationAttribute : FilterAttribute, IAuthorizationFilter
    {
        void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
        {
            ...
        }
    }
}

感谢您在这方面帮助我

【问题讨论】:

    标签: c# asp.net-core-3.1


    【解决方案1】:

    我认为您不了解 ASP.NET Core 的工作原理。没有System.Web.Mvc.Filters 命名空间,也没有FilterAttribute;任何与 MVC 相关的包都与旧版 ASP.NET 相关,因此与 Core 不兼容(因此您不能使用该命名空间),因此安装它们毫无意义。

    如果你有一个 ASP.NET MVC 应用程序并且你想将它升级到 Core,you should read the document that Microsoft has prepared for exactly that

    【讨论】:

    【解决方案2】:

    显然我发现的示例不是 .NET Core (???)

    我发现另一个来自 Microsoft 的文档说要使用 IAsyncPageFilter, IOrderedFilter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 2021-06-30
      • 1970-01-01
      • 2018-09-04
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多