IISHttpServer-未指定authenticationScheme,并且未找到DefaultChallengeScheme

时间:2019-05-06 14:33:16

标签: iis asp.net-core-webapi

我试图将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上下文,字符串方案,AuthenticationProperties属性)    在Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext上下文)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult结果)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext上下文)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext [TFilter,TFilterAsync](状态和下一个,范围和范围,对象和状态,布尔值和isCompleted)    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAlwaysRunResultFilters()    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()    在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()    在Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)    在Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)    在Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext上下文)    在Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)    在Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext,ISwaggerProvider swaggerProvider)    在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文)    在Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

Program.cs

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

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();
    }

0 个答案:

没有答案