Steve Fenton

Handle Legacy .aspx Page Requests In ASP.NET MVC

If you have a public web application that you are upgrading from Web Forms to ASP.NET MVC, you may find yourself wanting to capture requests to the now obsolete .aspx addresses.

By default, these requests won’t be passed to your application so you won’t be able to catch them using a route. So to get hold of them in your application you’ll need to make a change to your Web.config file to ensure .aspx requests are sent to your application:

<!-- ... -->
	  <!-- ... -->
	  <add name="AspxHandler" path="*.aspx" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

Once you have updated the Web.config, you can create a route to pass these requests to an action:

public static void RegisterRoutes(RouteCollection routes)
    // ...

        name: "AspxRoute",
        url: "{permalink}.aspx",
        defaults: new { controller = "LegacyRedirection", action = "Aspx" }

And within your controller you can do whatever you like with the request, for example redirect it to the new address, or display content, or whatever you like.

public class LegacyRedirectionController : Controller
    public ActionResult Aspx(string permalink)
        ViewBag.PermaLink = permalink;
	//TODO: redirect, or fetch content - you choose! 
        return View();

Written by Steve Fenton on