Azure Web App for Containers, Kestrel, and UseHttpsRedirection

·

2 min read

When testing the latest version of a docker image for an ASP.NET Core API the request sent never received a response when testing with Postman.

Error: Exceeded maxRedirects. Probably stuck in a redirect loop https://somesite.azurewebsites.net/route

Checking the logstream:

2021-02-23T00:12:45.373140644Z: [INFO]  info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
2021-02-23T00:12:45.373144644Z: [INFO]        Request finished in 0.5084ms 307

The 307 HTTP status code is a redirect.

Looking at the code we have a UseHttpsRedirection in the Configure method in Startup.cs:

app.UseHttpsRedirection();

There was no configuration in the ConfigureServices method such as:

services.AddHttpsRedirection(options =>
{
   options.HttpsPort = 443;
});

Note, I also added the above option to ConfigureServices and specified ASPNETCORE_HTTPS_PORT to 443. As well as port 80 for both to no avail.

This service was originally used with an IIS Reverse Proxy. After removing the UseHttpsRedirection, I was able to get a 200 status code back. I've followed the guidelines to enable the HTTPS Only option under the service app's TLS/SSL settings.

References