Windows Authentication with asp.net Kernel

Please provide guidance on implementing Windows authentication on Core RC2 + ASP.NET.

I see other SO questions that describe bearer authentication, like Media Identification with ASP.NET Core RC2 404 instead of 403

But that is not what I am looking for.

+8
asp.net-core .net-core
source share
3 answers

You can do this using WebListener, for example:

  • Open the project.json file and add the WebListener depending on:

    "dependencies" : { ... "Microsoft.AspNetCore.Server.WebListener": "0.1.0-rc2-final" ... } 
  • Add WebListener to commands (again in Project.json)

      "commands": { "weblistener": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener" }, 
  • In Startup.cs, specify WebHostBuilder to use WebListener with NTLM

      var host = new WebHostBuilder() // Some configuration .UseWebListener(options => options.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM) // Also UseUrls() is mandatory if no configuration is used .Build(); 

What is it!

+8
source share

This seems to no longer work in .Net Core 1.0.0 (final initial version). I am doing WebHostBuilder in the exact same way as mentioned above in Ivan Prodanov's answer; it starts, does not receive errors there, but HttpContext.User is not marked with a WindowsIdentity identifier. The following code used to work in ASP.Net 5 beta6:

in project.json:

 "version": "1.0.0" "dependencies": { "Microsoft.AspNetCore.Owin": "1.0.0", "Microsoft.AspNetCore.Server.WebListener": "0.1.0", 

in middleware class:

 public async Task Invoke(HttpContext context) { try { ClaimsPrincipal principal = context.User; // <-- get invalidcastexception here: WindowsIdentity winIdentity = (WindowsIdentity)principal.Identity; .... .... 
+4
source share

Check launchSettings.json file - change anonymousAuthentication to false

  "iisSettings": { "windowsAuthentication": true, "anonymousAuthentication": false, 

For deployment in iis, check out this core MVC Asp.Net Windows Authentication application in IIS

+3
source share

All Articles