Add a trailing slash at the end of each url?

后端 未结 6 672
傲寒
傲寒 2020-12-01 00:15

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 s

6条回答
  •  悲哀的现实
    2020-12-01 01:06

    Nice clean solution, codingbug!!

    Only problem I ran into was double trailing slashes for the home page in MVC3.

    Razor example:

    @Html.ActionLink("Home", "Index", "Home")
    

    Linked to:
    http://mysite.com//

    To fix this I tweaked the GetVirtualPath override:

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {       
        VirtualPathData path = base.GetVirtualPath(requestContext, values);       
    
        if (path != null && path.VirtualPath != "")       
            path.VirtualPath = path.VirtualPath + "/";       
        return path;       
    }
    

提交回复
热议问题