Remove Trailing Slash in ASP.NET MVC 4 Route to Application Root

别说谁变了你拦得住时间么 提交于 2019-12-03 08:55:19

Is there any way to prevent ASP.NET MVC routing from appending the trailing slash to the above route?

You should pass a trailing slash when the relative path is empty. If you somehow generate links with href localhost/IISApplicationName still the browser appends a "/" at the end (you can easily verify this in firebug, just type http://stackoverflow.com in the browser address bar and check the requests tab you can see the trailing "/").

This is because as per the HTTP/1.1,

the absolute path cannot be emtpy; if none is present in the original URI, it mut be given as "/" (the server root).

http://www.faqs.org/rfcs/rfc2616.html#ixzz0kGcaRbqU (section 5.1.2)

I recommend URL Rwrite Outbounds rules.

Creating Outbound Rules for URL Rewrite Module : URL Rewrite Module 2 : URL Rewrite Module : The Official Microsoft IIS Site

Sample config:

    <rewrite>
        <outboundRules>
            <rule name="RewriteSlash">
                <match filterByTags="A" pattern="^/IISApplicationName/$" />
                <action type="Rewrite" value="/IISApplicationName" />
            </rule>
        </outboundRules>
    </rewrite>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!