在ASP.NET Core 6 Web应用程序中使用Windows身份验证时,可能会出现“No default auth scheme with windows authentication”的错误。为了解决这个问题,需要对ASP.NET Core应用程序的配置文件进行调整。
在appsettings.json文件中,确保添加了Windows身份验证所需的配置数据。例如:
{
"Authentication": {
"Windows": {
"Enabled": true,
"Challenges": {
"Negotiate": true,
"NTLM": true
}
}
}
}
还需要在Startup.cs文件的ConfigureServices方法中调用AddAuthentication:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = "Windows";
})
.AddNegotiate()
.AddNTLM();
//…
}
最后,在Startup.cs文件的Configure方法中调用UseAuthentication:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//…
app.UseAuthentication();
//…
}
这样配置后,应用程序就可以使用Windows身份验证了。