Reputation: 1648
I try to create a filter with .NET Core 3.1
for some weird reason, many things cannot be found
The type or namespace name 'FilterAttribute' could not be found (are you missing a using directive or an assembly reference?)
first, System.Web.Mvc could not be found, so I uninstalled, reinstalled the microsoft apsnet mvc package
but I still get the same issue
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)
{
...
}
}
}
thanks for helping me on this
Upvotes: 0
Views: 1800
Reputation: 1648
so apparently the examples I found are not .NET Core (???)
I found another doc from Microsoft that says to use IAsyncPageFilter, IOrderedFilter instead
Upvotes: 0
Reputation: 29929
I don't think you understand how ASP.NET Core works. There is no System.Web.Mvc.Filters
namespace and no FilterAttribute
; any MVC-related packages relate to legacy ASP.NET and are therefore incompatible with Core (hence why you cannot use that namespace), so there's no point in installing them.
If you have an ASP.NET MVC application and you want to upgrade it to Core, you should read the document that Microsoft has prepared for exactly that.
Upvotes: 2