MVC RequireHttps entire site

前端 未结 9 1062
遇见更好的自我
遇见更好的自我 2020-12-23 13:24

I have read the previous posts about using the RequireHttpsAttribute to secure individual controllers:

ASP.NET MVC RequireHttps in Production Only

but is the

9条回答
  •  Happy的楠姐
    2020-12-23 13:48

    You could always add a check at the application level in your global.asax

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
       if (!HttpContext.Current.Request.IsSecureConnection)
       {
        Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
                                     + HttpContext.Current.Request.RawUrl);
       }
    }
    

提交回复
热议问题