Switching Between HTTP and HTTPS Automatically

Put this code in the Page Load event of ASP.Net

If (Request.ServerVariables("HTTPS") = "off") Then

Dim sname As String = Request.ServerVariables("SERVER_NAME")
Dim scname As String = Request.ServerVariables("SCRIPT_NAME")
Dim qstring As String = Request.ServerVariables("QUERY_STRING")
Dim Redirect_Path As String = "https://" & sname & scname
If qstring <> "" Then
Redirect_Path = "https://" & sname & scname & "?" & qstring End If
Response.Redirect(Redirect_Path)

End If