How can I programmatically force a webpage to use SSL?

How can I programmatically force a webpage to use SSL?

You can programmatically force your webpage to use SSL by using the following code in your page:

VB.NET

If (Request.ServerVariables("HTTPS") = "off") Then
 Response.Redirect("https://www.yourdomain.com/")
End If 


C#

if (Request.ServerVariables["HTTPS"] == "off")
{
 Response.Redirect("https://www.yourdomain.com/")
}