How to redirect HTTP to HTTPS in MVC application (IIS7.5)

前端 未结 11 2121
情歌与酒
情歌与酒 2020-11-29 21:39

I need to redirect my HTTP site to HTTPS, have added below rule but I am getting 403 Error when tried using http://www.example.com, it works fine when I type https://www.exa

11条回答
  •  一个人的身影
    2020-11-29 21:57

    I use the following in Global.asax:

    protected void Application_BeginRequest()
    {
      if (FormsAuthentication.RequireSSL && !Request.IsSecureConnection)
      {
        Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"));
      }
    }
    

提交回复
热议问题