Reputation: 3842
Having trouble enabling both Anonymous and Windows authentication working when using http.sys as webserver in ASP.NET core 2.0. It works fine when I host in IIS but refuses to work in http.sys server. Method tags [Authorize]
on HomeController Windows
action fails with HTTP 500 and never prompts for authentication.
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 );;
}
}
Exception
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()
Upvotes: 1
Views: 3248
Reputation: 3842
Need to add following to "services" section despite the fact that it's not hosted in IIS
services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
Upvotes: 1