首页 > 解决方案 > IISHttpServer - 没有指定 authenticationScheme,也没有找到 DefaultChallengeScheme

问题描述

我正在尝试将 Core WebAPI 2.2(InProcess 或 OutOfProcess)部署到 IIS 7.5。我得到以下错误,下面是代码。

失败:Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2] 连接 ID“15636497907840974971”,请求 ID“8000007e-0000-d900-b63f-84710c7967bb”:应用程序引发了未处理的异常。System.InvalidOperationException:未指定 authenticationScheme,也未找到 DefaultChallengeScheme。在 Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties) 在 Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext context) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult 结果)在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker。

程序.cs

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseIIS()
            .UseStartup<Startup>();   

启动.cs

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        // Configure services

        services.AddAuthentication(IISDefaults.AuthenticationScheme);

        ConfigureSwagger(services);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            // 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.UseAuthentication();
        // Enable middleware to serve generated Swagger as a JSON endpoint.
        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProject.Test V1");
        });

        app.UseMvc();
    }

标签: iisasp.net-core-webapi

解决方案


推荐阅读