I figured all of this out. There are four problems. I'll address them each individually.
- When configuring http.sys, a warning is issued about overriding local URLs
The UseHttpSys
extension method of IWebHostBuilder
accepts an options argument with a UrlPrefixes
property. However, this is not where you should configure URLs - even if you're using http.sys. You can hardcode them with the UseUrls
extension method of IWebHostBuilder
, but it would be better to pull it from configuration, which leads to the second problem:
- Configuration should be read from appsettings.json
To specify which URLs you want to run the application on, add them to the "urls" element in appsettings.json
, as follows:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"urls": "http://sharedhost.vbcoa.com:80/app/;https://sharedhost.vbcoa.com:443/app/"
}
Then you'll need to create a ConfigurationBuilder
object, add the appsettings.json
file to it, build the configuration (with the Build
method) and tell IWebHostBuilder
to use that configuration, with the UseConfiguration
extension method:
public static void Main(string[] args)
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
var hostBuilder = WebHost.CreateDefaultBuilder(args)
.UseConfiguration(configBuilder.Build())
.UseHttpSys()
.UseStartup<Startup>();
hostBuilder.Build().Run();
}
- Redirection goes to port 5001, not 443
HTTPS redirection is specified in the Configure
method of Startup
- 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 the ConfigureServices
method of Startup
. Add the following line to that method:
services.AddHttpsRedirection(options => { options.HttpsPort = 443; });
- Microsoft Edge won't show the web app, even though every other browser will
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:
- Make sure "Allow localhost loopback" is checked in Edge's "about:flags" page.
Launch a Command Prompt or Powershell Prompt as an Administrator and enter the following:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
That should do it!