How do you forward http request to a https url

后端 未结 6 527
孤独总比滥情好
孤独总比滥情好 2020-12-17 06:05

Like the question says, if I have a request for a page on my site like this

http://somename.something.here/Dada.aspx

to something like this

https://s

6条回答
  •  天涯浪人
    2020-12-17 07:00

    I prefer to (a) not redirect local connections (to ease development under VS), and (b) use a UriBuilder instead of a string.Replace as it's a bit more exact.

    if (!Request.IsLocal && !Request.IsSecureConnection) {
        var ub = new UriBuilder(Request.Url);
        ub.Scheme = Uri.UriSchemeHttps;
        ub.Port = -1; // use default port for scheme
        Response.Redirect(ub.Uri.AbsoluteUri, true);
        return;
    }
    

提交回复
热议问题