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?
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash is generally used to distinguish a directory which has the trailing slash from a file that does not have the trailing slash.
If your site has a directory structure, it's more conventional to use a trailing slash with your directory URLs (for example, example.com/directory/ rather than example.com/directory ), but you can choose whichever you like. Be consistent with the preferred version. Use it in your internal links.
The addition of a slash at the end of a URL instructs the web server to search for a directory. This speeds the web page loading because the server will retrieve the content of the web page without wasting time searching for the file.
To do so, go to the “Settings -> Permalinks” section and, depending on your situation, either add or delete the last slash. The “Custom Structure” field ends with a slash, so all other WordPress URLs will have the trailing slash. Likewise, if it is not present there, the slash will be missing in your website's URLs.
The RouteCollection Class now has a AppendTrailingSlash boolean which you can set to true for this behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With