I'm having a ton of problems getting an ASP.NET Core 2.1 web application up and running. I need it to run under http.sys (WebListener) on a shared port (80 or 443). I'd also like it to automatically redirect from http (80) to https (443). Of course, I don't want to hard code the listener addresses for http.sys - I need to pull those from a configuration file, but they're hard coded for now. I reserved the appropriate URLs with netsh, but when I run the app I get a warning:
warn: Microsoft.AspNetCore.Server.HttpSys.MessagePump[0]
Overriding address(es) 'http://sharedhost.vbcoa.com:80/app/, https://sharedhost.vbcoa.com:443/app/'. Binding to endpoints added to UrlPrefixes instead.
The app starts, but I can't browse to it with Microsoft Edge at all. Any other web browser is fine - as long as I disable HTTPS. For some reason, the application is forwarding to port 5001, instead of 443.
I figured all of this out. There are four problems. I'll address them each individually.
The
UseHttpSysextension method ofIWebHostBuilderaccepts an options argument with aUrlPrefixesproperty. However, this is not where you should configure URLs - even if you're using http.sys. You can hardcode them with theUseUrlsextension method ofIWebHostBuilder, but it would be better to pull it from configuration, which leads to the second problem:To specify which URLs you want to run the application on, add them to the "urls" element in
appsettings.json, as follows:Then you'll need to create a
ConfigurationBuilderobject, add theappsettings.jsonfile to it, build the configuration (with theBuildmethod) and tellIWebHostBuilderto use that configuration, with theUseConfigurationextension method:HTTPS redirection is specified in the
Configuremethod ofStartup- that functionality comes out of the box. However, by default it will forward to port 5001, even if you have another port specified in your bound URLs from above. To override it, you need to inject HTTPS redirection options via a service. That's handled in theConfigureServicesmethod ofStartup. Add the following line to that method:This is a problem with localhost loopback isolation in Windows Store apps. It seems to affect Windows 10 Enterprise, as discussed here: Microsoft Edge is not able to recognize localhost. To correct it, you need to do two things:
Launch a Command Prompt or Powershell Prompt as an Administrator and enter the following:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbweThat should do it!