【问题标题】:I get an error when I try to execute this method app.UseCookieAuthentication(); in MVC (.net 5)当我尝试执行此方法时出现错误 app.UseCookieAuthentication();在 MVC (.net 5) 中
【发布时间】:2021-03-01 10:08:18
【问题描述】:

严重性代码描述项目文件行抑制状态 错误
CS1061“IApplicationBuilder”不包含“UseCookieAuthentication”的定义,并且找不到接受“IApplicationBuilder”类型的第一个参数的可访问扩展方法“UseCookieAuthentication”(您是否缺少 using 指令或程序集引用?) IdentityServer C:\ Users\A01\source\repos\Identity provider\src\IdentityServerAspNetIdentity\Startup.cs 189 活动

enter image description here

【问题讨论】:

标签: cookies asp.net-core-mvc .net-5 asp.net-core-5.0


【解决方案1】:

“IApplicationBuilder”不包含“UseCookieAuthentication”的定义,并且找不到接受“IApplicationBuilder”类型的第一个参数的可访问扩展方法“UseCookieAuthentication”(您是否缺少 using 指令或程序集引用?)

请注意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

【讨论】:

    猜你喜欢
    • 2013-01-08
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 2021-12-24
    • 2023-01-17
    • 1970-01-01
    相关资源
    最近更新 更多