Redirect from HTTP to HTTPS - IIS 7.5

前端 未结 5 1792
孤独总比滥情好
孤独总比滥情好 2021-01-04 19:08

I have implemented https on my application and now i\'m trying to make IIS redirect all http request to https, so that the user doesn\'t even notice this change.

I h

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 19:53

    you can make a simple check on the global.asax, on beginRequest, something like this code:

    protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
    
            if(!app.Response.Request.IsSecureConnection)
            {
                app.Response.Redirect(Request.RawUrl.Replace("http://","https://"), true);
                return;
            }
        }
    

    ps. I did not have check this code, I just type it now.

提交回复
热议问题