ASP.NET MVC 2 Preview 2 Route Request Not Working

Posted by Kezzer on Stack Overflow See other posts from Stack Overflow or by Kezzer
Published on 2009-10-08T08:59:16Z Indexed on 2010/06/11 8:52 UTC
Read the original article Hit count: 175

Filed under:

Here's the error:

The incoming request does not match any route.

Basically I upgraded from Preview 1 to Preview 2 and got rid of a load of redundant stuff in relation to areas (as described by Phil Haack). It didn't work so I created a brand new project to check out how its dealt with in Preview 2. The file Default.aspx no longer exists which contains the following:

public void Page_Load(object sender, System.EventArgs e)
{
  // Change the current path so that the Routing handler can correctly interpret
  // the request, then restore the original path so that the OutputCache module
  // can correctly process the response (if caching is enabled).

  string originalPath = Request.Path;
  HttpContext.Current.RewritePath(Request.ApplicationPath, false);
  IHttpHandler httpHandler = new MvcHttpHandler();
  httpHandler.ProcessRequest(HttpContext.Current);
  HttpContext.Current.RewritePath(originalPath, false);
}

The error I received points to the line httpHandler.ProcessRequest(HttpContext.Current); yet in newer projects none of this even exists. To test it, I quickly deleted Default.aspx but then absolutely nothing worked, I didn't even receive any errors. Here's some code extracts:

Global.asax.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Intranet
{
  public class MvcApplication : System.Web.HttpApplication
  {
    public static void RegisterRoutes(RouteCollection routes)
    {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

      AreaRegistration.RegisterAllAreas();

      routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = "" }
      );
    }

    protected void App_Start()
    {
      RegisterRoutes(RouteTable.Routes);
    }
  }
}

Notice the area registration as that's what I'm using.

Routes.cs

using System.Web.Mvc;

namespace Intranet.Areas.Accounts
{
  public class Routes : AreaRegistration
  {
    public override string AreaName
    {
      get { return "Accounts";  }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
      context.MapRoute("Accounts_Default", "Accounts/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" });
    }
  }
}

Check the latest docs for more info on this part. It's to register the area. The Routes.cs files are located in the root folder of each area.

Cheers

© Stack Overflow or respective owner

Related posts about asp.net-mvc