Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net core HttpsRedirectionMiddleware Failed to determine the https port for redirect

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

like image 350
NewtonCode Avatar asked Dec 11 '18 12:12

NewtonCode


People also ask

What is Hsts in asp net core?

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.

What is UseHttpsRedirection?

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.


2 Answers

I had this warning on debug mode. You just need to "Enable SSL" and the warning goes away.

enter image description here

Or if you use IIS, you can edit the Advanced Settings to enable https. enter image description here

like image 44
Weihui Guo Avatar answered Sep 21 '22 14:09

Weihui Guo


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>(); 
like image 193
CodeCaster Avatar answered Sep 17 '22 14:09

CodeCaster