Alex Rivera | Logout

Detecting https from HttpContext in .net?

Asked 2010-10-04T14:40:19.307
26

I've inherited a pile of code for a web app which contains oodles of hard-coded paths. I've been tasked with trying to get it to run using https://.

Other than detecting "https://" in the URL is there a more inband way to detect that the current context is https?

Looking for something like:

System.Web.HttpContext.Current.Request.Url.Protocol.ToString()

Edit
Report

1 Answer

2

I use this code to auto redirect to https

If HttpContext.Current.Request.IsSecureConnection.Equals(False) Then
    Response.Redirect("https://" + Request.ServerVariables("HTTP_HOST") & HttpContext.Current.Request.RawUrl)
End If
answered 2012-08-14T13:19:21.107

Your Answer