1
在ASP.NET核心2.0中使用http.sys作为web服务器时,无法启用匿名和Windows身份验证工作时遇到问题。当我在IIS中托管但拒绝在http.sys服务器中工作时,它工作正常。 HomeController上的方法标签[Authorize]
Windows
操作失败,HTTP 500并且从不提示进行身份验证。如何在ASP.NET Core 2.0中同时使用匿名和Windows身份验证
的Program.cs
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.Negotiate |
AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = true;
options.UrlPrefixes.Add("http://localhost:5000");
})
HomeController.cs
[Authorize]
public class HomeController : Controller
{
[Authorize]
public IActionResult Windows()
{
return Content ("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType);
}
[AllowAnonymous]
public IActionResult Anonymous()
{
return Content ("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType);;
}
}
异常
An unhandled exception occurred while processing the request.
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
Microsoft.AspNetCore.Authentication.AuthenticationService+<ChallengeAsync>d__11.MoveNext()
当您收到一个500错误,你应该总是张贴的确切异常消息,是怎么回事的人应该帮助你? – Tseng
增加了例外。 –