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
Vous devez vous connecter pour publier un commentaire.
Alors que la rédaction du post, je me suis souvenu de venir à travers ce paragraphe du guide de migration. Il dit d'ajouter
à la
ConfigureServices
fonction.J'ai d'abord pensé que ce ne serait pas s'appliquer à HttpSys, donné le nom au complet de la constante (en particulier la
IISIntegration
m'a jeté). En outre, de cette écriture, la HttpSys documentation complètement ne parvient pas à le mentionner.Pour ceux qui visent le plein .NET Framework, cela nécessite l'installation de la
Microsoft.AspNetCore.Authentication
Package NuGet.MODIFIER
Comme Tratcher points, il est une autre constante de la
HttpSys
espace de noms, vous devriez plutôt utiliser:Vous pouvez remplacer IISIntegration.IISDefaults avec HttpSys.HttpSysDefaults, ils ont la même valeur.
Merci! Mise à jour de la réponse.
OriginalL'auteur Andreas
Andreas réponse m'a mis sur le droit chemin, mais c'est ce qui a fonctionné pour moi:
Ajout d'un paquet de référence pour
Microsoft.AspNetCore.Authentication
et puis pour de Démarrage.cs
using Microsoft.AspNetCore.Server.IISIntegration;
OriginalL'auteur fiat