on a .NET website, what's the best way of redirecting html pages to http if someone tries to access them by https?

I'm redirecting aspx pages using Global.asax but that doesn't pick up html pages...



IIS can be configured to do the redirects itself, if possible this will be the best approach.

Another approach would be to continue to use your redirect in Global.asax but configure IIS to send more requests, including requests for .html files to the .net run time. You should be able to do this on a website by website basis. You can then create an HttpHandler which will have the code to do the redirecting. This can be configured in the web.config by adding a line like

   <add verb="*" path="*.html" type="You.Namespace.Handlers.RedirectHandler"/>
   <add verb="*" path="*.htm" type="You.Namespace.Handlers.RedirectHandler"/>

Only use this approach if all of this IIS site (https://example.com) is a redirect.

If you serve real .html pages through .net runtime you will have a performance cost.

Hope that helps.

  • I managed to map the html files to the ASP.NET ISAPI extension (Aspnet_isapi.dll) using IIS. This generates an entry under <system.webServer>. But how do I link it to the <httpHandlers> section ??
    – user441365
    Jun 6 '12 at 14:54

Try using javascript

<script type="text/javascript">
function LeaveHTTPS() 
        var newURL=window.location.replace("https","http");
windows.onload= function() {LeaveHTTPS()}
  • it needs to be tested though... will have to do minor modifications i guess
    – Sirwani
    Jun 6 '12 at 13:46
  • Thanks but I would rather use something more robust
    – user441365
    Jun 6 '12 at 13:47
  • You would then need to create a file for every existing .html in the site with this redirect. Also the http redirects can provide much more information to search engins, proxies, caches, browsers e.g. 301, 302, 303, 304, 305, and 307. In this case the best response would be 301 Moved Permanently. Jun 6 '12 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy