Wednesday, September 23, 2015

Redirect http to https in iis using custom errors

Suggested Videos
Part 100 - Secure Socket Layer in asp.net
Part 101 - Implementing SSL in asp.net 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".
<html>
<head>
   <title>
      Redirecting to HTTPS
   </title>
</head>
<script language="JavaScript">
function redirectHttpToHttps()
{
    var httpURL= window.location.hostname + window.location.pathname;
    var httpsURL= "https://" + httpURL;
    window.location = httpsURL;
}
redirectHttpToHttps();
</script>
<body>
</body>
</html>

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.


If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment