I added this simple piece of middleware to my asp.net core web app according to this post: Redirect to HTTPS
if (!env.IsLocalhost())
{
app.Use(async (context, next) =>
{
if (context.Request.IsHttps)
{
await next();
}
else
{
var withHttps = "https://" + context.Request.Host + context.Request.Path;
context.Response.Redirect(withHttps);
}
});
app.UseMiddleware<RedirectHttpMiddleware>();
}
After deploying to Azure I have an infinite redirect loop.
I have verified that the middleware is causing the infinite loop (if I comment it out the loop goes away) and that IsHttps is indeed true.
Does anybody have a suggestion as to why this happens?