Remove Traiing Foward Slash using UrlRewritingNet

ぃ、小莉子 提交于 2019-12-11 05:33:46

问题


i'm doing some work on a legacy asp.net and umbraco site. It's using UrlRewritingNet to set up rules for url manipulation.

I'd like to create a rule in the UrlRewritingNet file to remove the trailing slash from the url.

eg. http://www.test.com/index.aspx/ to http://www.test.com/index.aspx

Can you please help.


回答1:


<add name="noendslash" 
            virtualUrl="^(.*)/$" 
            rewriteUrlParameter="IncludeQueryStringForRewrite" 
            redirect="Application"
            destinationUrl="~$1"
            ignoreCase="true" />



回答2:


In the later versions of IIS in the url rewrite section you can set up these SEO rules without having to change code. Just 'add rules' in the 'url rewrite' section of the website:




回答3:


You can use the TrimEnd() method.

return inputString.TrimEnd('/'); // .NET 2 or newer

or

return inputString.TrimEnd(new char[] { '/' }); // legacy


来源:https://stackoverflow.com/questions/15611511/remove-traiing-foward-slash-using-urlrewritingnet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!