Zachary Scott
Zachary Scott

Reputation: 21162

Asp.Net 4: How to route to a web form in an MVC site?

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.

Upvotes: 0

Views: 1004

Answers (2)

Kevin LaBranche
Kevin LaBranche

Reputation: 21078

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.

Upvotes: 3

Matthew Abbott
Matthew Abbott

Reputation: 61589

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?

Upvotes: 2

Related Questions