Handling ASP.net routes using n slashes using regex

I need to use a URL like this:

http://mydomain.com/Box/Categ1/Categ2/Categ3/.../CategN/id1,id2,id3,...,idN

Then I tried to create a new route this way ...

routes.MapRoute(
    "Box",
    "Box/{data}",
    new { controller = "Box", action = "Index"},
    new { data = @"([a-zA-Z0-9-,]+/?)+" }
);

But that just doesn't work. If I use char instead of "/" (slashes), it works fine. Can slashes be used? I really would like to see a URL like this.

+5
source share
1 answer

If you want to set the data variable to everything that comes after Box, just use the catch-all parameter.

routes.MapRoute(
    "Box",
    "Box/{*data}",
    new { controller = "Box", action = "Index"}
);
+11
source

All Articles