Using Kestrel and WebListener Together with ASP.NET Core for Windows Authentication

    Out of the box, ASP.NET Core projects are loaded with Kestrel support. Unfortunately, Kestrel doesn't support Windows Authentication when running the application in a standalone process, but WebListener does. It's a drag to configure WebListener in order to test applications with Windows Authentication during development, just to realize that it doesn't support the reverse-proxy that IIS uses.

    Yes, I could run Visual Studio and execute the ASP.NET Core application in IIS Express every single time or even publish to IIS, but what if I just simply want to get latest from Git and execute a dotnet run? I can't. Luckily I have a solution to this issue in the form of an IWebHostBuilder extension.

    I noticed the only differences between running a standalone ASP.NET Core app and one used within IIS are a few environment variables. I chose to look for the existence of the APP_POOL_CONFIG variable to determine whether to add in WebListener or Kestrel. This seems to be the quick and easy way to switch between both, depending on whether it's running in standalone or from within an IIS app pool. 

An example for usage of UseWebListenerAndKestrel is attached below

I'm hoping that something will be done to solve this in the future, but for now this'll do.