没有配置身份验证处理程序来验证方案:Windows

时间:2018-03-30 20:11:49

标签: c# asp.net-core windows-authentication

我没有看到任何解决特定于“Windows”身份验证方案的错误的问题。我在IIS中托管了一个ASP.NET Core 2.0应用程序,我尝试按照这些说明设置Windows Auth:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?tabs=aspnetcore2x但是在授权时我得到标题错误异常:

  

应用程序抛出了未处理的异常。   System.InvalidOperationException:没有配置身份验证处理程序来验证方案:Windows      在Microsoft.AspNetCore.Authentication.AuthenticationService.d__10.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在Microsoft.AspNetCore.Authorization.Policy.PolicyEvaluator.d__2.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter.d__15.MoveNext()   ---从抛出异常的先前位置开始的堆栈跟踪结束---      在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)......

具体来说,我的代码位于ConfigureServices

services.AddAuthentication(IISDefaults.AuthenticationScheme);

services.AddMvc(opt =>
{
    var defaultPolicy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .AddAuthenticationSchemes(IISDefaults.AuthenticationScheme)                       
        .Build();
    opt.Filters.Add(new AuthorizeFilter(defaultPolicy));
});

Configure

app.UseAuthentication();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();

使我的情况与众不同的另一个原因是我使用以下软件包引用来定位.NET Framework 4.7(不是.NET Core)。是否有一个我遗漏的实际执行身份验证?

<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />

对此错误的任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

我认为您错过了在Properties / launchSettings.json中将该属性设置为true的属性;

"windowsAuthentication": true