Fix: HTTPS redirect loop in ASP.NET Core production

Published: Jun 01, 2026 · By Kumar Kunal

The Error

Site never loads in production. Browser says:

ERR_TOO_MANY_REDIRECTS

Quick Fix - 1 Minute

Your load balancer/reverse proxy already handles HTTPS. Disable ASP.NET's redirect.

var app = builder.Build();

if (!app.Environment.IsDevelopment()) { app.UseHsts(); } else { app.UseHttpsRedirection(); // Only in Dev }

Why This Happens

Azure/AWS/Nginx terminates SSL and forwards HTTP to your app. Your app sees HTTP and redirects to HTTPS. The proxy sees HTTPS, forwards as HTTP. Infinite loop.

Best Practice for.NET 8

1. Trust the proxy: Add app.UseForwardedHeaders() before UseHttpsRedirection

2. Check X-Forwarded-Proto: Make sure proxy sets this header

3. Dev vs Prod: Only use UseHttpsRedirection locally

Related Dev Fixes

Found this helpful?

Master C# with our complete course. Real apps, real skills, job-ready in 2 hours.

Share this fix: Twitter LinkedIn

Comments on Fix: HTTPS redirect loop in ASP.NET Core production (0)

No comments yet. Be the first to share your thoughts!