I'm using OVH Server with SSL Gateway Free where i've hosted my MVC5 App.
When i was trying to force only HTTPS connection my browser displayed:
"ERR_TOO_MANY_REDIRECTS".
I was trying various things and solutions but none of them worked.
I enabled SSL in my project properties, tried to redirect through URL Rewrite on my IIS followed by this tutorial and many others, use [RequireHttps]
on my BaseController
and also a lots of configuration of Application_BeginRequest()
in Global.asax.
f.e.:
protected void Application_BeginRequest()
{
if (!Context.Request.IsSecureConnection)
{
// This is an insecure connection, so redirect to the secure version
UriBuilder uri = new UriBuilder(Context.Request.Url);
if (!uri.Host.Equals("localhost"))
{
uri.Port = 443;
uri.Scheme = "https";
Response.Redirect(uri.ToString());
}
}
}
Have no idea how to force only HTTPS connection.