在每个URL的末尾添加斜线? [英] Add a trailing slash at the end of each url?

查看:100
本文介绍了在每个URL的末尾添加斜线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我这里有一个小问题。我需要在我工作的现场每个URL的末尾添加尾部的斜杠。我定义的站点内的所有链接,有结尾的斜线,像这样:


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>

虽然这工作正常还是有一个很小的问题:它与来自调用RedirectToAction生成的URL是()。例如:

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"}
            );

不过所需的斜线不会被自动添加!

我抬头一看这个<一个href=\"http://stackoverflow.com/questions/1077206/adding-a-trailing-slash-for-specific-redirection-rules\">question这<一个href=\"http://stackoverflow.com/questions/645853/add-slash-to-the-end-of-every-url-need-rewrite-rule-for-nginx\">question但这些,是完全不同的,我没有使用任何URL重写库我只是使用asp.net mvc的路由系统。

所以,你说什么家伙?

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?

推荐答案

该RouteCollection类现在有一个AppendTrailingSlash布尔值,你可以设置为true这一行为。

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

这篇关于在每个URL的末尾添加斜线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆