C# 在ASP.NET MVC 5应用程序无限加载中重定向到https

C# 在ASP.NET MVC 5应用程序无限加载中重定向到https,c#,asp.net-mvc,http,https,asp.net-mvc-5,C#,Asp.net Mvc,Http,Https,Asp.net Mvc 5,我正在尝试对ASP.NET MVC 5应用程序的所有请求强制执行从http到https的重定向。目前,我已将[RequireHttps]注释添加到所有控制器操作中,并已将以下内容添加到Global.asax: protected void Application_BeginRequest() { System.Diagnostics.Debugger.Break(); if (!Context.Request.IsSecureConnection) {

我正在尝试对ASP.NET MVC 5应用程序的所有请求强制执行从http到https的重定向。目前,我已将
[RequireHttps]
注释添加到所有控制器操作中,并已将以下内容添加到
Global.asax

  protected void Application_BeginRequest()
{
    System.Diagnostics.Debugger.Break();

    if (!Context.Request.IsSecureConnection)
    {
        // Only insert an "s" to the "http:", and avoid replacing wrongly http: in the url parameters
        Response.Redirect(Context.Request.Url.ToString().Insert(4, "s"));
    }
}
当使用https时,此操作会被触发,但http请求只会无休止地加载,而不会触发该操作。我还将其发布到了一个临时服务器,结果相同:https工作正常,但http不会被重定向,只会无休止地加载

由于客户端将通过包含http链接地址的电子邮件访问此应用程序,因此能够重定向非常重要


如何正确重定向到https?

重定向到https应该从IIS或ApacheOh dang完成好的,我想我必须与系统管理员联系。假设我想在应用程序中完成。谢谢