【问题标题】:AuthenticationBuilder does not contain a definition for AddAzureAdAuthenticationBuilder 不包含 AddAzureAd 的定义
【发布时间】:2019-07-13 13:08:44
【问题描述】:

我正在遵循here 的教程并尝试使用 Azure Ad 启用 OpenId Connect,这是我尝试添加到 Startup.cs 文件的代码。

    services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
        .AddAzureAd(options => Configuration.Bind("AzureAd", options))
        .AddCookie();

AddAzureAd 有红色下划线并显示以下错误消息:

“AuthenticationBuilder”不包含“AddAzureAd”的定义 并且没有可访问的扩展方法“AddAzureAd”接受第一个 可以找到“AuthenticationBuilder”类型的参数(你是 缺少 using 指令或程序集引用?)

我尝试过的步骤:

  1. 清理并重建解决方案
  2. 重启视觉工作室

但这并不能解决问题。有谁知道造成这种情况的其他原因是什么?

【问题讨论】:

  • 看来您需要添加对Microsoft.AspNetCore.Authentication.AzureAD.UI 的引用。此外,它似乎是AddAzureAD 而不是AddAzureAd
  • @KirkLarkin 感谢您的回复,但它仍然不起作用.. :(
  • 同时添加对包的引用d更改为D?
  • @KirkLarkin 是的,它奏效了……我不敢相信我就因为这个被困了 2 个小时……非常感谢!!!
  • @KirkLarkin,您可以发布您的建议作为答案。

标签: c# azure authentication asp.net-core azure-active-directory


【解决方案1】:

我在一些愚蠢的事情上浪费了完全相同的时间,就像不添加参考一样。 这个问题的答案是这样的:

 dotnet add package Microsoft.AspNetCore.Authentication.AzureAD.UI --version 2.2.0

请注意,您可能添加了另一个与身份验证相关的参考,但不是您遇到问题的那个。

【讨论】:

    【解决方案2】:

    我必须在我的启动文件中添加一条 using 语句。

    using Microsoft.AspNetCore.Authentication;
    

    【讨论】:

    • 不幸的是,这对我没有帮助:(
    【解决方案3】:

    就我而言,我必须:

    1. 在 *.cproj 中添加对 Microsoft.AspNetCore.Authentication.AzureAD.UI 的引用

    2. 在 Startup.cs 中添加using Microsoft.AspNetCore.Authentication

    3. 使用.AddAzureAD(options => Configuration.Bind("AzureAd", options));

    希望这对某人有所帮助,因为我在上面浪费了半个小时。

    【讨论】:

      【解决方案4】:

      我遇到了类似的错误,但对我来说是:

      CS1061 'AuthenticationBuilder' 不包含对 'AddGoogle' 和没有可访问的扩展方法 'AddGoogle' 接受 可以找到“AuthenticationBuilder”类型的第一个参数(你是 缺少 using 指令或程序集引用?)

      通过安装NuGet解决Microsoft.AspNetCore.Authentication.Google

      https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google

      https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-6.0

      【讨论】:

        猜你喜欢
        • 2021-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多