Add a trailing slash at the end of each url?

Galilyou picture Galilyou · Sep 6, 2009 · Viewed 26.7k times · Source

I have a little problem here. I need to add a trailing slash at the end of each url in the site I'm working on. I defined all the links inside the site to have a trailing slash like so:

<a href="/register/">Register</a>

While this works fine there's still one tiny issue: it's with the generated urls that come from calling RedirectToAction(). For example:

return RedirectToAction("Register", "Users");

Will cause the url to change to /register with no trailing slash. I modified my routing system as so:

  routes.MapRoute("register",
                        "register/",
                        new {controller = "Users", action = "Register"}
            );

Still the required trailing slash doesn't get added automatically!
I looked up this question and this question but these are totally different as I'm not using any url rewriting libraries, i'm just using asp.net mvc routing system.
So what do you say guys?

Answer

Schmidty picture Schmidty · Nov 7, 2013

The RouteCollection Class now has a AppendTrailingSlash boolean which you can set to true for this behavior.