当我尝试执行此方法时出现错误 app.UseCookieAuthentication();在 MVC (.net 5) 中

I get an error when I try to execute this method app.UseCookieAuthentication(); in MVC (.net 5)

Severity Code Description Project File Line Suppression State Error
CS1061 'IApplicationBuilder' does not contain a definition for 'UseCookieAuthentication' and no accessible extension method 'UseCookieAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) IdentityServer C:\Users\A01\source\repos\Identity provider\src\IdentityServerAspNetIdentity\Startup.cs 189 Active

enter image description here

'IApplicationBuilder' does not contain a definition for 'UseCookieAuthentication' and no accessible extension method 'UseCookieAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

请注意,UseCookieAuthentication 方法已过时。它似乎已从 ASP.NET Core 3.0 及更高版本中删除。

您可以在 ConfigureServices 方法中使用 AddAuthentication().AddCookie 配置 cookie 身份验证。

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.cookieappbuilderextensions.usecookieauthentication?view=aspnetcore-2.2

此外,这篇文档介绍了如何配置和使用cookie认证,您可以参考。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-5.0