Saturday, 9 November 2013

Redirect from HTTP to HTTPS using Error Pages - ASP.Net

In this article we are going to handle the redirection of Http request to Https by using a error pages. when an error raised due to 403.4 code our error page is called , in that htm we are creating a redirect function in javascript which redirect to the secured site.To do this follow the simple steps

1 . Enable the RequireSSl in SSL settings for web application in IIS.
2. create a Intermediate HTM error page.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Redirect to Https</title>
    <script type="text/javascript" language="javascript">
        function HttpToHttps() {

            var https = window.location.hostname + window.location.pathname;
            https = "https://" + https;
            window.location = https;
        }
        HttpToHttps();
    </script>
</head>
<body>
</body>
</html>


 3. Configure the IIS for error handling click the IIS server and select the Error Pages icon then Add a new status code by click the Add button Then mention the status code as 403.4 and give the error handle htm path in file path. Now click the Edit feature settings and select the custom error pages and select the file path for handle the error 403.4. Now the redirect will happen from http to https.

From this article you can learn how to do the redirection from http to https using error pages 

No comments:

Post a Comment