MVC3 MapRoute, slash parameter

How to create a MapRoute that accepts slashes without considering it a new parameter? If url

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

I want one parameter to take everything after localhost (root / p1 / default.aspx). Usually, this would require three parameters, because there are two slashes, and maproute separates the slash parameters. Therefore, if the route looks something like this:

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

then {path} selects everything, although the url contains slashes.

+4
source share
1 answer

You can use the general route:

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

and then:

 public ActionResult Index(string path) { ... } 
+8
source

All Articles