ASP.NET Core 2.0 HttpSys l'Authentification Windows ne parvient pas à Autoriser l'attribut (InvalidOperationException: Pas de authenticationScheme a été spécifié)

Je suis en train de migrer une ASP.NET de Base 1.1 champ d'application de ASP.NET Core 2.0.

L'application est très simple et comporte les éléments suivants:

  • Hébergés sur HttpSys (anciennement WebListener)
  • À l'aide de l'authentification Windows: options.Authentication.Schemes = AuthenticationSchemes.NTLM
  • Permettant l'authentification anonyme: options.Authentication.AllowAnonymous = true (car il y a des contrôleurs qui ne nécessitent pas d'authentification)
  • Contrôleurs qui nécessitent une authentification sont décorées avec le [Authorize] attribut.

Le projet compile et lance l'amende juste. Il sert également des actions de contrôleurs qui ne nécessite pas d'authentification.

Cependant, dès que j'ai touché un contrôleur avec la [Authorize] attribut, j'obtiens l'exception suivante:

System.InvalidOperationException: No authenticationScheme was specified,
and there was no DefaultChallengeScheme found.
at Microsoft.AspNetCore.Authentication.AuthenticationService.<ChallengeAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.ChallengeResult.<ExecuteResultAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeResultAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

J'ai commencé à bidouiller avec les modèles de projet et de remarqué que j'ai pu reproduire ce facilement en utilisant le modèle standard ASP.NET de Base de l'Application Web (Modèle-Vue-Contrôleur) avec l'Authentification Windows.

Le Programme.cs fichier a été modifié comme suit:

    public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = 100;
options.MaxRequestBodySize = 30000000;
options.UrlPrefixes.Add("http://localhost:5000");
})
.UseStartup<Startup>()
.Build();

Cela vient directement de la HttpSys documentation. Aussi j'ai ajouté le [Authorize] attribut à la HomeController classe. Maintenant, il va produire exactement la même exception, comme illustré.

J'ai trouvé quelques Débordement de Pile postes (ici, ici et ici), mais aucune d'entre elles traite de la plaine de l'Authentification Windows (et les réponses ne semblent pas généraliser).

OriginalL'auteur Andreas | 2017-08-22