R – MVC: “The incoming request does not match any route.” – with a default request

asp.net-mvcurl-routing

I am getting this error only SOMETIMES (apparently randomly, though I know there's really no such thing in computers).

I'm working on an MVC (release 1) site in VS 2008. The machine is running Windows 7 with IIS 7, but this instance is running under the Webserver built into VS (Cassini?). When I do an F5 to start running it, I will sometimes get an exception trap at the 4th line of the Page_Load method of Default.aspx.cs:

httpHandler.ProcessRequest(HttpContext.Current);

The exception method is:
The incoming request does not match any route.

Examining the HttpContext.Current.Request object shows a path of "/", and a rawUrl of "/Default.aspx?" – i.e, your normal empty request to a site.

The MapRoutes routine is pretty much standard except for a couple of IgnoreRoutes lines (ignore "pics/{*imgfile}", and ignore "{*favicon}"). The Application_Start routine has configuration for a StructureMap, and a call to SetControllerFactory before the call to RegisterRoutes, but it otherwise standard.

Usually, if I restart VS, the problem goes away. (And almost always if I restart the machine).

Any clues?

Thanks.

Best Answer

Set a default Page. F5 in asp.net will launch to whatever page is selected. However since in MVC, your View may or may not have an associated controller function, it can be trying to call an action that doesn't exist. Open up your project properties and set the debug start page to your site home controller action.