Die Windows-Authentifizierung .net Core 2.1-Anwendung

Habe ich eine .net Core 2.1 MVC-Anwendung hostet eine Eckige 6-Anwendung. Ich benutze Visual Studio 2017 15.7.3. Ich bin versucht, Windows-Authentifizierung, aber ich habe Probleme. Ich habe folgte die Dokumentation und mein Programm.cs und Inbetriebnahme.cs unter:

Programm.cs:

using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Web;
using System;

namespace CoreIV_Admin_Core
{
public class Program
{
    public static void Main(string[] args)
    {
        var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

        try
        {
            logger.Debug("init main");
            CreateWebHostBuilder(args).Build().Run();
        }
        catch (Exception ex)
        {
            //NLog: catch setup errors
            logger.Error(ex, "Stopped program because of exception");
            throw;
        }
        finally
        {
            //Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
            NLog.LogManager.Shutdown();
        }
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            //.UseHttpSys(options =>
            //{
            //   options.Authentication.Schemes = AuthenticationSchemes.NTLM | AuthenticationSchemes.Negotiate;
            //   options.Authentication.AllowAnonymous = false;
            //})
            .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information);
            })
            .UseNLog(); //NLog: setup NLog for Dependency injection
}
}

Start.cs:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace CoreIV_Admin_Core
{
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.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);

        services.AddMvc()
               .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();
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true
            });
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();

        app.UseStaticFiles();

        app.UseCookiePolicy();

        app.UseHttpContext();

        app.UseAuthentication();

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

            routes.MapSpaFallbackRoute(
                name: "spa-fallback",
                defaults: new
                {
                    controller = "Home",
                    action = "Index"
                });
        });
    }
 }
}

Wenn ich die Auskommentierung der .UseHttpSys Abschnitt im Programm.cs und drücken Sie play in Visual Studio Debuggen, ist es fast sofort Stoppt das debug-Sitzung, und der folgende Fehler wird im Ereignisprotokoll angezeigt:

"Anwendung" MACHINE/WEBROOT/APPHOST/myapp' mit physikalischen root
'C:\Users\me\myapp' erstellte Prozess mit Kommandozeilen - 'C:\Program Dateien
(x86)\Microsoft Visual
Studio\2017\Professional\Common7\IDE\Extensions\Microsoft\Web
Tools\ProjectSystem\VSIISExeLauncher.exe -argFile
"C:\Users\me\AppData\Local\Temp\tmpFCA6.tmp"' aber nicht zu hören auf
die jeweiligen port '28353'".

Wenn ich versuche mit .UseHttpSys auskommentiert, das debugging funktioniert, aber ich bin nicht in der Lage zu sein, ordnungsgemäß authentifiziert.

  • Bitte Lesen Sie Dokumentation vorsichtig. Sie mischen Kestrel Zeug mit HttpSys. Sie werden nie in der Lage sein, um die Authentifizierung mit HttpSysDefaults.AuthenticationScheme mit Kestrel.
InformationsquelleAutor LanceM | 2018-06-05
Schreibe einen Kommentar