Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Redirect http to https in IIS using custom errors - Part 103

Suggested Videos
Part 100 - Secure Socket Layer in
Part 101 - Implementing SSL in web application
Part 102 - Redirect http to https in IIS

In this video we will discuss about redirecting users from HTTP to HTTPS, using "IIS Error Pages". In the previous session, we discussed about redirecting users using "URL ReWrite" module. 

Custom error pages can be set at the server level or at a specific application level in IIS. In this demo, we will discuss about setting custom error pages at the server level. There are 3 simple steps.

Step 1: 
Make sure "Require SSL" option from "SSL Settings" is checked for your web application in IIS. Now, browse the web site, using HTTP, and you will receive the following error. Pay attention to HTTP error code - 403.4, which we will be using later.
HTTP Error 403.4 - Forbidden
The page you are trying to access is secured with Secure Sockets Layer (SSL).

Step 2:
Copy and paste the following HTML in a notepad and save it as "RedirectToHttps.htm" in "C:\inetpub".
      Redirecting to HTTPS
<script language="JavaScript">
function redirectHttpToHttps()
    var httpURL= window.location.hostname + window.location.pathname;
    var httpsURL= "https://" + httpURL;
    window.location = httpsURL;

Step 3:
1. In IIS, select the "Server Name" and double click "Error Pages" to open the feature.
2. Click on "Add" link under "Actions" 
3. Set Status Code = 403.4, File Path = C:\Inetpub\RedirectToHttps.htm and click "OK"
4. Now click "Edit Feature Settings" link under "Actions"
5. Select "Custom Error Pages" and Path = C:\inetpub\RedirectToHttps.htm

Now, access the application using HTTP. You will be automatically redirected to HTTPS.

1 comment:

  1. This comment has been removed by the author.


If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.