1
votes

I have a problem with the wildcard route that I wonder if anyone can help on, I have a route as below

routes.MapRoute(
            "ReportRoute", 
            "Report/{*path}", 
            new { controller = "Home", action = "Index"})
            .RouteHandler = new ReportPathRouteHandler();

where the routehandler splits the path into its correct parts to get the correct report and this works great, if I put in a route www.mysite.com/report/folder1/folder2/report then I'll get what I'm looking for however my problem is if I have a link like www.mysite.com/report/folder1/report, the *path is only folder1/report and the routing really doesn't like this, in fact it doesn't even hit my route handler, just goes straight to 'resource can't be found' server error page. I tried to get around this by adding a new route before the wildcard as below

routes.MapRoute(
            "ReportRoute2",
            "Report/{path}/{name}",
            new { controller = "Home", action = "Index" });

where the Controller takes Path and Name as two string parameters but still no joy, has anyone got any ideas or pointers as to what can fix this issue? Thanks for your help.

1

1 Answers

0
votes

The first example should be fine (except that odd .RouteHandler = new ReportPathRouteHandler(); at the end). What does your controller action look like? Does it take a "string path" as a parameter?