简体   繁体   English

没有注册“Microsoft.Identity.Abstractions.IAuthorizationHeaderProvider”类型的服务

[英]No service for type 'Microsoft.Identity.Abstractions.IAuthorizationHeaderProvider' has been registered

Edit: Used a pre release of a nuget, reverted back to older version and no longer got this error.编辑:使用 nuget 的预发布版,恢复到旧版本,不再出现此错误。

I am getting this error (Title), but cannot figure out what is wrong.我收到此错误(标题),但无法弄清楚出了什么问题。 App works fine locally, publishes to Azure but gives me HTTP error 500 when trying to open the website.应用程序在本地运行良好,发布到 Azure 但在尝试打开网站时给我 HTTP 错误 500。

I guess I might be missing a service in my Startup class?我想我的 Startup class 中可能缺少一项服务? This is the Startup.cs:这是 Startup.cs:

using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;

namespace AppOwnsData
{
    using AppOwnsData.Models;
    using AppOwnsData.Services;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;

    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)
        {
            // Get the scopes from the configuration (appsettings.json)
            var initialScopes = Configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');
            
            // Add sign-in with Microsoft
            services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))

                // Add the possibility of acquiring a token to call a protected web API
                .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)

                // Enables controllers and pages to get GraphServiceClient by dependency injection
                // And use an in memory token cache
                .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
                .AddDistributedTokenCaches();
            
            
            
            
            // Register AadService and PbiEmbedService for dependency injection
            services.AddScoped(typeof(AadService))
                    .AddScoped(typeof(PbiEmbedService))
                    .AddScoped(typeof(PowerBiServiceApi));

            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });

            // Enables a UI and controller for sign in and sign out.
            services.AddRazorPages()
                .AddMicrosoftIdentityUI();

            // Loading appsettings.json in C# Model classes
            services.Configure<AzureAd>(Configuration.GetSection("AzureAd"))
                    .Configure<PowerBI>(Configuration.GetSection("PowerBI"));
            
            /*// Add the UI support to handle claims challenges
            services.AddServerSideBlazor()
                .AddMicrosoftIdentityConsentHandler();*/
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
    }
}

This is the error I am getting from the call stack in azure application insight:这是我在 azure application insight 中从调用堆栈中得到的错误:

System.InvalidOperationException: at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) System.InvalidOperationException:在 Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(Microsoft.Extensions.DependencyInjection.Abstractions,Version=7.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)在 Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(Microsoft.Extensions.DependencyInjection.Abstractions,Version=7.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60)
at Microsoft.Identity.Web.GraphServiceCollectionExtensions+<>c.b__1_0 (Microsoft.Identity.Web.MicrosoftGraph, Version=2.0.6.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae)在 Microsoft.Identity.Web.GraphServiceCollectionExtensions+<>c.b__1_0(Microsoft.Identity.Web.MicrosoftGraph,Version=2.0.6.0,Culture=neutral,PublicKeyToken=0a613f4dd989e8ae)

I used a pre release of Microsoft.Identity.Web Nuget that caused this issue.我使用了导致此问题的 Microsoft.Identity.Web Nuget 的预发行版。 After reverting back to an older version it worked fine.恢复到旧版本后,它工作正常。

暂无
暂无

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

相关问题 没有注册类型“Microsoft.AspNet.Identity.UserManager”的服务 - No service for type 'Microsoft.AspNet.Identity.UserManager' has been registered 没有注册“Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]”类型的服务 - No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered 没有为“Microsoft.AspNetCore.Identity.UserManager`1[testLogin.Areas.Identity.Data.testLoginUser]”类型注册服务 - No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[testLogin.Areas.Identity.Data.testLoginUser]' has been registered 没有注册 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext' 类型的服务 - No service for type 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext' has been registered 没有注册 'Microsoft.AspNetCore.Identity.UserManager`1[System.Model.User]' 类型的服务 - No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[System.Model.User]' has been registered 没有注册“Microsoft.Extensions.Logging.ILoggingBuilder”类型的服务 - No service for type 'Microsoft.Extensions.Logging.ILoggingBuilder' has been registered 没有为“Microsoft.AspNetCore.Http.HttpContextAccessor”类型注册服务 - No service for type 'Microsoft.AspNetCore.Http.HttpContextAccessor' has been registered 没有注册类型为“Microsoft.AspNetCore.Mvc ...”的服务 - No service for type 'Microsoft.AspNetCore.Mvc..." has been registered 没有注册“Microsoft.Framework.Runtime.ILibraryManager”类型的服务 - No service for type 'Microsoft.Framework.Runtime.ILibraryManager' has been registered 没有注册“Microsoft.Extensions.Http.DefaultHttpClientFactory”类型的服务 - No service for type 'Microsoft.Extensions.Http.DefaultHttpClientFactory' has been registered
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM