Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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...

Thanks

share|improve this question

migrated from stackoverflow.com Jun 7 '12 at 10:17

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 1 down vote accepted

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

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

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.

share|improve this answer
    
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

<head>
<script type="text/javascript">
function LeaveHTTPS() 
{
        if(window.location.toString().search("https")>=0){
        var newURL=window.location.replace("https","http");
    window.location=newURL;}
}
windows.onload= function() {LeaveHTTPS()}
</script>
</head>
share|improve this answer
    
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. –  David Waters Jun 6 '12 at 14:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.