Missing HSTS header issues in Asp.net core Web API

Add below code in Startup class but still issue exists. Kindly provide some suggestion to fix the issue.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see Enforce HTTPS in ASP.NET Core | Microsoft Docs.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
});

}
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

services.AddHsts(options =>
{
    options.Preload = true;
    options.IncludeSubDomains = true;
    options.MaxAge = TimeSpan.FromDays(60);
});

services.AddHttpsRedirection(options =>
{
    options.RedirectStatusCode = (int) HttpStatusCode.TemporaryRedirect;
    options.HttpsPort = 5001;
});

}