Tuesday, April 12, 2011

Force ASP.NET Page to Use secure HTTP (https) with SSL/TLS

Sometimes we want to provide encryption and secure identification of the server creating a secure channel over an insecure network.
In that case we need HTTPS connection which ensures reasonable protection e.g. for payment transactions.
Ok let’s see how this thing works.
Say that your page is as follows: http://www.domain.com/yourpage.aspx
Ok, just add this code inside Load Event Handler and voila! That’s it!

If Not Request.IsSecureConnection Then
   Response.Redirect("https://www.domain.com/yourpage.aspx ")
End If

No comments: