1

我在 ASP.NET Core 2.2 中有一个需要 Windows 身份验证的应用程序。为了拥有完整的开发环境,我们使用 HTTP.sys,因为它允许我们通过观察程序获得完整的 NTLM 支持:

dotnet watch run

问题发生,当我们部署到 IIS 10.0

启动文件配置如下:

services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
services.Configure<IISOptions>(options =>
{
    options.AutomaticAuthentication = true;
});

程序配置如下:

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost
            .CreateDefaultBuilder(args)
            .UseIISIntegration()
            .UseHttpSys(options =>
            {
                options.Authentication.Schemes = AuthenticationSchemes.NTLM;
                options.Authentication.AllowAnonymous = false;
            })
            .UseStartup<Startup>()
            .UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
                .ReadFrom.Configuration(hostingContext.Configuration)
                .Enrich.FromLogContext()
                .WriteTo.Console());
}

在本地开发方面,一切都按预期进行。当我们部署时,我们有以下错误:

如果我们设置 web.confighostingModel="InProcess"

2019-10-16 17:03:14.320 +02:00 [Fatal] Application startup exception
System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
   at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

如果我们删除它,那么 Out Process:

2019-10-16 17:10:38.151 +02:00 [Fatal] Application startup exception
System.InvalidOperationException: Scheme already exists: Windows
   at Microsoft.AspNetCore.Authentication.AuthenticationSchemeProvider.AddScheme(AuthenticationScheme scheme)
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware..ctor(RequestDelegate next, ILoggerFactory loggerFactory, IOptions`1 options, String pairingToken, Boolean isWebsocketsSupported, IAuthenticationSchemeProvider authentication, IApplicationLifetime applicationLifetime)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
4

0 回答 0