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
No comments yet. Be the first to share your thoughts!