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

NewtonCode picture NewtonCode · Dec 11, 2018 · Viewed 45.3k times · Source

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

Answer

CodeCaster picture CodeCaster · Dec 11, 2018

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>();