Posted By

Scooter on 09/21/11


Tagged


Versions (?)

Force SSL


 / Published in: VB.NET
 

URL: http://reusablecode.blogspot.com/2011/09/force-ssl-in-vbnet.html

The technique that I had used for years in classic ASP didn't seem to work reliably in ASP.NET, so I switched to this based on articles on various blogs. Request and Response are fully qualified because I had trouble getting System.Web.HttpContext.Current to import in AppCode. Place the function in an AppCode library, import the library on your page, and call ForceSSL() at the top of Page_Load().

  1. ' Force communication using Secure Socket Layer.
  2. Public Shared Sub ForceSSL()
  3. If Not System.Web.HttpContext.Current.Request.IsSecureConnection Then
  4. ' redirect visitor to SSL connection
  5. System.Web.HttpContext.Current.Response.Redirect(System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "https://"))
  6. End If
  7. End Sub

Report this snippet  

You need to login to post a comment.