小编Woj*_*jna的帖子

在 MVC5 应用程序上强制使用 HTTPS 时出现 ERR_TOO_MANY_REDIRECTS

我将 OVH Server 与 SSL Gateway Free 一起使用,我在其中托管了我的 MVC5 应用程序。

当我试图仅强制 HTTPS 连接时,我的浏览器显示:

“ERR_TOO_MANY_REDIRECTS”。

我正在尝试各种事情和解决方案,但没有一个奏效。

我在我的项目属性中启用了 SSL,尝试通过我的 IIS 上的 URL 重写重定向,然后是本教程和许多其他教程[RequireHttps]在我的BaseController以及Application_BeginRequest()Global.asax 中的许多配置中使用。

铁:

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());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

不知道如何强制只使用 HTTPS 连接。

c# asp.net iis ssl https

1
推荐指数
1
解决办法
1752
查看次数

标签 统计

asp.net ×1

c# ×1

https ×1

iis ×1

ssl ×1