Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ASP.NET MVC ignoring my trailing slash?

Consider the following route:

    routes.MapRoute(
        "Service", // Route name
        "service/", // URL with parameters
        new {controller = "CustomerService", action = "Index"} // Parameter defaults
        );

Using Url.Action("Service", "CustomerService") produces an url of /service instead of the expected /service/

Is there any way to get this to work, or do I have to resort to implementing my own routing deriving from RouteBase?

like image 868
andreialecu Avatar asked Jun 22 '09 12:06

andreialecu


1 Answers

Legenden - there is no immediate solution to the problem. You may have run across Jason Young's blog post about the issue, which is very informative. Scott Hanselmann posted a reply to it here, basically stating that he didn't think it was a big deal, and if it is, you can leverage the new IIS7 rewrite module to solve it.

Ultimately though, you might want to look at a solution that was posted by murad on a similar question on StackOverflow: Trailing slash on an ASP.NET MVC route

like image 191
womp Avatar answered Sep 27 '22 22:09

womp