简体   繁体   English

类型或名称空间名称“ AzureAD”在名称空间“ Microsoft.AspNetCore.Authentication”中不存在

[英]The type or namespace name 'AzureAD' does not exist in the namespace 'Microsoft.AspNetCore.Authentication'

I have an issue after following an example project from the following link https://azure.microsoft.com/en-gb/resources/samples/active-directory-aspnetcore-webapp-openidconnect-v2/ . 从以下链接https://azure.microsoft.com/en-gb/resources/samples/active-directory-aspnetcore-webapp-openidconnect-v2/跟随示例项目后,我遇到了问题。 It doesn't build at all and complains of the following 2 errors, 它根本无法构建,并且抱怨以下两个错误,

i) error CS0234: The type or namespace name 'AzureAD' does not exist in the namespace 'Microsoft.AspNetCore.Authentication' (are you missing an assembly reference?) i)错误CS0234:类型或名称空间名称“ AzureAD”在名称空间“ Microsoft.AspNetCore.Authentication”中不存在(您是否缺少程序集引用?)

ii) error CS0234: The type or namespace name 'HttpsPolicy' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) 1>Done building project "WebApp-OpenIDConnect-DotNet.csproj" -- FAILED. ii)错误CS0234:类型或名称空间名称'HttpsPolicy'在名称空间'Microsoft.AspNetCore'中不存在(您是否缺少程序集引用?)1>完成构建项目“ WebApp-OpenIDConnect-DotNet.csproj”-失败。

I have followed some suggestions from elsewhere, which involved running "dotnet restore" on the project, but this hasn't worked. 我遵循了其他地方的一些建议,其中包括在项目上运行“ dotnet restore”,但这没有用。

Have any idea on what I need to do here? 对我在这里需要做什么有任何想法吗?


File in question is below. 有问题的文件如下。 This is "Startup.cs" taken from https://azure.microsoft.com/en-gb/resources/samples/active-directory-aspnetcore-webapp-openidconnect-v2/ . 这是从https://azure.microsoft.com/en-gb/resources/samples/active-directory-aspnetcore-webapp-openidconnect-v2/中获取的“ Startup.cs”。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace active_directory_aspnetcore_webapp_openidconnect_v2_master
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
                .AddAzureAD(options => Configuration.Bind("AzureAd", options));

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

So it turned out the documentation was outdated and that the project required references to some of the missing libraries, which was easily done in the end. 因此,事实证明该文档已过时,并且该项目需要引用一些缺少的库,最后很容易做到。 To resolve the issue I did the following, 为了解决这个问题,我做了以下工作,

i) Right click on "Dependencies" and click on "Manage NuGet packages...". i)右键单击“依赖项”,然后单击“管理NuGet软件包...”。
ii) Click on "Browse" and search for "Microsoft.AspNetCore.Authentication.AzureAD.UI" and install this library. ii)单击“浏览”并搜索“ Microsoft.AspNetCore.Authentication.AzureAD.UI”并安装此库。
iii) Click on the "Installed" tab and update the existing libraries. iii)单击“已安装”选项卡并更新现有库。

Rebuild your solution. 重建您的解决方案。 It is also worth noting that the namespace value in both "HomeController.cs" and "AccountController.cs" should match each other. 还值得注意的是,“ HomeController.cs”和“ AccountController.cs”中的名称空间值应相互匹配。 So for example they both should be "namespace WebApp_OpenIDConnect_DotNet.Controllers". 因此,例如,它们都应为“命名空间WebApp_OpenIDConnect_DotNet.Controllers”。 There was a conflict with one of my files as it referenced "namespace active_directory_aspnetcore_webapp_openidconnect_v2_master.Controllers", which caused a compile error. 我的一个文件发生冲突,因为它引用了“命名空间active_directory_aspnetcore_webapp_openidconnect_v2_master.Controllers”,从而导致了编译错误。

Install following packages with nuget: 使用nuget安装以下软件包:

install-package Microsoft.AspNetCore.DataProtection install-package Microsoft.AspNetCore.Antiforgery install-package Microsoft.AspNetCore.Authentication.Core install-package Microsoft.AspNetCore.Authentication.Cookies install-package Microsoft.AspNetCore.Authentication.JwtBearer install-package Microsoft.AspNetCore.Authentication.OAuth install-package Microsoft.AspNetCore.Authentication.OpenIdConnect install-package Microsoft.AspNetCore.Authentication install-package Microsoft.AspNetCore.Authorization.Policy install-package Microsoft.AspNetCore.Authorization install-package Microsoft.AspNetCore.Cors install-package Microsoft.AspNetCore.Diagnostics.Abstractions install-package Microsoft.AspNetCore.Html.Abstractions install-package Microsoft.AspNetCore.JsonPatch install-package Microsoft.AspNetCore.Localization install-package Microsoft.Extensions.Localization.Abstractions install-package Microsoft.AspNetCore.Localization install-package Microsoft.AspNetCore.Mvc.Abstractions install-package Microsoft.AspNetCore.Routing.Abstractions install-package Microsoft.AspNetCore.Mvc.Abstractions install-package Microsoft.AspNetCore.Mvc.Analyzers install-package Microsoft.AspNetCore.ResponseCaching.Abstractions install-package Microsoft.AspNetCore.Routing install-package Microsoft.Extensions.DependencyInjection install-package Microsoft.AspNetCore.Mvc.Core install-package Microsoft.AspNetCore.Mvc.ApiExplorer install-package Microsoft.AspNetCore.Mvc.Cors install-package Microsoft.Extensions.Localization install-package Microsoft.AspNetCore.Mvc.DataAnnotations install-package Microsoft.AspNetCore.Mvc.Formatters.Json install-package Microsoft.AspNetCore.Razor.Language install-package Microsoft.CodeAnalysis.Razor install-package Microsoft.AspNetCore.Mvc.Razor.Extensions install-package Microsoft.AspNetCore.Mvc.ViewFeatures install-package Microsoft.AspNetCore.Razor install-package Microsoft.AspNetCore.Razor.Runtime install-package Microsoft.Extensions.Caching.Abstractions install-package Microsoft.Extensions.Caching.Memory install-package Microsoft.Extensions.FileProviders.Composite install-package Microsoft.AspNetCore.Mvc.Razor install-package Microsoft.AspNetCore.Mvc.Localization install-package Microsoft.AspNetCore.Mvc.RazorPages install-package Microsoft.AspNetCore.Mvc.TagHelpers install-package Microsoft.AspNetCore.Razor.Design install-package Microsoft.AspNetCore.Mvc install-package Microsoft.AspNetCore.Authentication.AzureAD.UI

And optionally this: install-package Microsoft.NET.Sdk.Razor 并且可以选择这样: install-package Microsoft.NET.Sdk.Razor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 命名空间“Microsoft”中不存在类型或命名空间名称“AspNetCore” - The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' 命名空间名称身份验证在命名空间 Microsoft.AspNetCore.Components.WebAssembly.Authentication 中不存在 - Namespace name Authentication does not exist in the namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication 命名空间“Microsoft.AspNetCore”中不存在类型或命名空间“OData” - The type or namespace 'OData' does not exist in the namespace 'Microsoft.AspNetCore' 命名空间“Microsoft.AspNetCore.Mvc.Razor”中不存在类型或命名空间名称“RuntimeCompilation” - the type or namespace name 'RuntimeCompilation' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.Razor' 命名空间“Microsoft.AspNetCore.Razor”中不存在类型或命名空间名称“Hosting” - The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' 命名空间“Microsoft”中不存在类型或命名空间名称“AspNetCore”(您是否缺少程序集引用?) - The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) Blazor:命名空间“Microsoft.AspNetCore.Mvc.ApplicationParts”中不存在类型或命名空间名称“ApplicationPartAttributeAttribute” - Blazor: The type or namespace name 'ApplicationPartAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' 命名空间“Microsoft.AspNetCore”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?) - The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) 命名空间“Microsoft”中不存在类型或命名空间名称“TeamFoundation” - The type or namespace name 'TeamFoundation' does not exist in the namespace 'Microsoft' 命名空间“Microsoft”中不存在类型或命名空间名称“Azure” - The type or namespace name 'Azure' does not exist in the namespace 'Microsoft'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM