Search code examples
asp.net-corehsts

Production never redirect to https even api is enable for https redirect


I am working on asp.net core 2.1 API. The api is working as expected on all environment. recently we enable it for HSTS headers. so added below code in startup.cs -> ConfigureServices method

services.AddHsts(options =>
            {
                options.Preload = true;
                options.IncludeSubDomains = true;
            });
services.AddHttpsRedirection(options =>
            {
                options.RedirectStatusCode = StatusCodes.Status301MovedPermanently;
                options.HttpsPort = int.Parse(443);
            });

When I check response from postman on dev environment for http request it give me 302 redirect status code. which is as expected

But on Production for http request, It gives me 404 File or directory not found.

''''''''''''''''''''' In Configure method we have '''''''''

app.UseHsts()
   .UseHttpsRedirection();

I am expecting that on Production also I should get 302 status code instead of 404.

Did I miss any other setting. Why postman is show 404 on production but 302 on dev envirment when code is same on both envirment


Solution

  • I found "http" binding is missing on server. Adding http along with https works for me.