1

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()
Gregory Suvalian
  • 2,895
  • 1
  • 23
  • 48

1 Answers1

1

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);

Per ASP.NET Core 2.0 HttpSys Windows Authentication fails with Authorize attribute (InvalidOperationException: No authenticationScheme was specified)

Gregory Suvalian
  • 2,895
  • 1
  • 23
  • 48