I am trying to host an ASP.net Core Web Application in a windows service. I am able to create a self contained deployment and created the windows service. My web application is configured to have port 5000 for http and 5001 for https. Within the application , I use a HttpsRedirectMiddleware.
When I start the windows service , it is only possible to browse the web page over http and throws following error from the Https redirect middleware.
Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware Failed to determine the https port for redirect.
Is there any extra configuration needed to expose a port for https communication?
Github Code Sample
Posted on: 22-01-2017 6 Comments. This is a continuation to the previous article on Enforcing HTTPS. While redirecting all non-secure requests to secure URLs is good, a man-in-the-middle can still hijack the connection before the redirect.
UseHttpsRedirection causes an automatic redirection to HTTPS URL when an HTTP URL is received, in a way that forces a secure connection. Once the first HTTPS secure connection is established, the strict-security header prevents future redirections that might be used to perform man-in-the-middle attacks.
I had this warning on debug mode. You just need to "Enable SSL" and the warning goes away.
Or if you use IIS, you can edit the Advanced Settings to enable https.
See the documentation for various ways of configuring a non-default HTTPS port.
Which approach suits your scenario best depends on how your application is set up and hosted. You could for example add a setting:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSetting("https_port", "5001") .UseStartup<Startup>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With