Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to enable SSL certificate in IIS 6 and convert http to https under Global.asax? Also is it possible to test http to https auto redirection. I mean if user types http instead of https after SSL enabled it must redirect to https. Url Rewrite already tried but didn't work. Another code is as follows under Global.asax and called under Application_Begin Request.
C#
private void RedirectToCorrectSSLScheme()
 {
     Uri pageRequest = Request.Url;
     string requestPath = pageRequest.GetLeftPart(UriPartial.Path).ToLower();

      requestPath = Server.UrlDecode(requestPath);
     // PageIsSecure returns if the given page should be secure or not. I
     //maintain a list of secure pages or
     //secure directory in an XML config.
   //  bool securePage = GetSecurePages().PageIsSecure(requestPath);
     //Instead of localhost we can set the IP Address of Dubai server
     if (pageRequest.Scheme == "https" && pageRequest.Host.Contains("localhost") && requestPath.Contains(".aspx"))
     {
         //Response.Redirect("http://" + pageRequest.Host + pageRequest.PathAndQuery, true);
         Response.Redirect(requestPath, true);
     }
     //Added by Alex to check  external url of qatar server
     //Instead of localhost we can set the IP Address of Dubai server
     if (pageRequest.Scheme == "http" && pageRequest.Host.ToString()!="localhost"  && requestPath.Contains(".aspx"))

     {
        //Response.Redirect("https://" + pageRequest.Host + pageRequest.PathAndQuery, true);

        Response.Redirect(requestPath, true);
     }
 }


Still the issue persists locally.
Posted
Updated 29-Jan-14 3:09am
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900