Redirects Using 404 Error Handling in ASP.NET 2.0 on Shared Hosting (Part 1)


I recently made some changes to an ASP.NET web site on a shared hosting plan. There were some old web pages with HTML extensions that were replaced by newer pages with ASPX extensions. For example, I had an old page called clubteams.html and a new page called: teams.aspx. I wanted to make sure that visitors with links to the old pages would arrive at the new pages rather than seeing some obscure “not found” error.

This is a common enough issue and there are a number of ways to approach it on an ASP.NET website. But the devil is in the details, so they say, and it turns out that there are a lot of details involved in getting this right. In this series of blog entries, I’ll walk through the steps I took, share the lessons I learned and hopefully provide some answers for others seeking to do similar redirects in shared hosting environments.


Choosing an Approach

There are a number of methods for redirecting visitors from outdated web pages to their replacement pages. Here’s a list of some of the methods, grouped by required access level:

IIS Methods – Requires IIS Access

  • IIS Page Specific Redirects
  • IIS Custom Error Message Pages

ASP.NET Methods – No IIS Access Required

  • Custom HTTP Handler
  • URL Rewriting
  • ASP.NET URL Mapping
  • ASP.NET Custom Error Pages

The ASP.NET methods only work for file-types that IIS passes to ASP.NET for processing. A typical IIS configuration does not hand off HTML pages to ASP.NET. Since the incoming URLs I wanted to redirect were going to be HTML pages, that pretty much seemed to rule out using ASP.NET processing.

I next looked at the IIS methods. The web host for the web site in question did not provide a direct way to configure IIS page-specific redirects, so that was out. The host did, however, provide a nice UI for configuring IIS custom error pages for a web site.

How would using a custom error page help me redirect old pages to new pages? IIS helps us out here by handing the custom error pages a query string that looks something like this:


That query string provides enough information to detect the visitor’s intended destination. From that, I can match against a list of obsolete pages and, where a mapping exists, redirect the visitor to the appropriate new page.

The added benefit of using error handling to do the redirects is that my site would also gain a much more user friendly error page than the default generic error pages provided by IIS or ASP.NET.

So I now had my approach mapped out. In my next blog entry in this series, I’ll describe how I implemented the IIS custom error page.


11/17/2007 12:00:23 PM #

Trackback from Agile Web Technologies

Redirects Using 404 Error Handling in ASP.NET 2.0 on Shared Hosting (Part 3)

Agile Web Technologies