Search code examples
asp.netsslhttps

How do you check if the current page is using SSL in ASP.Net?


I have a site that, by design and client preference, can be served using HTTP or HTTPS. The client company simply chooses whether or not to link to our site using the http:// or https:// and IIS does the rest. A feature is being added to a page which deals with sensitive information that should only ever be viewed over SSL. Clients have agreed that this additional feature should be disabled on this page when not using an HTTPS connection.

In the Page_Load event I would like to add an IF statement that checks to see if the page is currently being viewed over HTTPS in order to show or disable this optional feature. I can probably read the URL to see if it begins with https:// but worry that the approach is insecure.

Is there a property that can be checked to test for HTTPS during the Page_Load event?


Solution

  • You're looking for Request.IsSecureConnection.