0

This question by Nick Craver implements routing to web forms like this:

routes.MapPageRoute("defaultRoute", "{*value}", "~/Missing.aspx");

However we get an error of Route data must contain an item named controller.

Is it possible to route to a web form?

We need to "catch" and route within routing rather than not hitting any routes then defaulting to the actual name. I don't think routing is specific to MVC, although we are routing to a web form that exists within an MVC site.

Community
  • 1
  • 1
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205

2 Answers2

3

I think you will need to add an IgnoreRoute in your RegisterRoutes method.

routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

This will tell MVC to not try to route this like it would normally. This is for .Net 4.0.

Here is some more details on this.

EDIT - SINCE MY INITIAL ABOVE ANSWER....

Scott Hanselman just created a nice post on integrating the two environments. Have a look at it. I imagine it is something in the initial setup of everything that may have been missed or not configured correctly that will be the culprit.

Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
  • Any particular reason for the downvote? Would be nice to know if someone would explain why they thought my answer was "bad".... :-) – Kevin LaBranche Jan 05 '11 at 20:43
  • 1
    My guess is something to do with the `IgnoreRoute` as I don't think that's the 'preferred' way, but if your method was used you'd likely also need to use `RouteExistingFiles = true` as the default is false. – Dan Atkinson Jan 05 '11 at 21:31
  • @Dan - Nice comment on RouteExistingFiles = true. I will have to look that up. – Zachary Scott Jan 07 '11 at 04:12
  • 1
    We should have a rally or nice turn around badge.... Going from -1 to +2. Sweet! :-) Glad my edit helps @dr-zim! :-) – Kevin LaBranche Jan 07 '11 at 14:17
2

Although Routing was introduced with ASP.NET MVC its actually a separate mechanism. For your issue, are you entirely sure you are using MapPageRoute instead of MapRoute?

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129