stationfour is a web design and marketing agency located in jacksonville, florida

301 Redirects on non ASP.NET pages with Mosso

Over the past few days I've been going back and forth with the support team at Mosso. They are great by the way. However, we couldn't seem to find a solution for the problem that I was having. I needed to return 301 redirects for .html pages and have them redirect to their proper .aspx pages in a newly redesigned website.

Traditionally, I would have just added a ISAPI filter within IIS to map all .html files to be parsed by the isapi.dll engine. This would force ASP.NET to attempt to parse the page. At that point, I would have included a bit of code at the top of the .html page to return the 301 redirect. Unfortunately, I could not get access to IIS b/c Mosso is a shared hosting environment and modifying server settings was not an option. 

I then attempted to add some handlers to my web.config file like this: 

<httpHandlers>
      <add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>

This would have told ASP.NET to run anything with the .html extension thru the default handler for .aspx pages. So, I tested it locally using Cassini (the internal web server for Visual Studio). Well, that caused my application to not compile. ASP.NET didn't know how to go about building the html pages since I was not passing thru ASP.NET. Quick fix:

<buildProviders>
        <add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>

I added a bit to the <configuration> tab in the web config to let ASP.NET know I want to use the default page builder to attempt to build the .html pages. Now my application compiled just fine. I went about my task of putting code chunks on every one of the old pages and uploaded them to the Mosso servers to test. And....nothing... All of my code just came thru as plain text is the .html files. Bummer! I had searched until the end of the internet and hadn't found much. The support guys were very helpful but still, nothing was working.

So, I took a wild guess. I crossed my fingers and hoped I could force the .html pages thru the isapi.dll and removed the <httpHandlers> config in my web.config and added the following:

<system.webServer>
    <handlers>
      <add name="Wildcard" path="*.html" verb="*" modules="IsapiModule" resourceType="Unspecified" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" />
    </handlers>
</system.webServer>

Now it works! So, if you have any problems with Mosso or any other shared hosting account, you can do your 301 Redirects referencing the isapi.dll in your web.config. Then just add chunks of code at the top of each .html page to specify the redirect like this:

<%@ Page Language="C#" %>
<%

       Response.Status = "301 Moved Permanently";
       Response.AddHeader("Location","http://www.websitename.com/default.aspx");

%>

Good luck!

Comments

Add comment