4

How would i create a MapRoute that accepts slashes without considering it a new parameter? If the url is

http://localhost/root/p1/default.aspx

I want one parameter to pick up everything after localhost (root/p1/default.aspx). Normally it would take three parameters for this because there are two slashes, and maproute separates the parameters by slash. So if the route looks something like

routes.MapRoute(
   "URLMapRoute",
   "{path}",
   new { controller = "Home", action = "Index", path = "default.aspx" }
);

then {path} picks up everything, even though the url contains slashes.

Anton Gildebrand
  • 3,641
  • 12
  • 50
  • 86

1 Answers1

8

You could use a catchall route:

routes.MapRoute(
    "URLMapRoute",
    "{*path}",
    new { controller = "Home", action = "Index", path = "default.aspx" }
);

and then:

public ActionResult Index(string path)
{
    ...
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • @Darin Dimitrov: Any help on this one? http://stackoverflow.com/questions/24932519/mvc-how-to-manage-slahses-in-route-parameters/ – Daniel Peñalba Jul 24 '14 at 13:19