Removing a Slash in ASP.NET MVC 4 Route to Application Root

In my ASP.NET MVC 4 application, RouteConfigI registered the following default route:

routes.MapRoute("Default", "{controller}/{action}/{id}",
    new { controller = "home", action = "index", id = UrlParameter.Optional });

Now, in Razor views, I want to create a URL for my application root as follows:

<a href="@Url.Action("index", "home")">Home</a>

The generated URL contains a trailing slash; clicking on the link opens the localhost / IISApplicationName / page. However, I want the URL not to contain the trailing slash, so that the URL is localhost / IISApplicationName. Creating routes for other activities, such as / Account / Login, does not create URLs with trailing slashes — it's just the route associated with my application root.

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

(I know that I can redirect the URL, including the slash, without it, but I would rather have the router generate the correct route URL in the first place.)

+5
source share
2 answers

Is there a way to prevent ASP.NET MVC from spreading by adding a trailing slash to the above route?

, . - href localhost/IISApplicationName, "/" ( firebug, /fooobar.com/... "", "/" ).

, HTTP/1.1,

emtpy; URI, "/" ( ).

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

0

URL Rwrite Outbounds.

URL- URL- : URL- Rewrite Module 2: URL-: Microsoft IIS

:

    <rewrite>
        <outboundRules>
            <rule name="RewriteSlash">
                <match filterByTags="A" pattern="^/IISApplicationName/$" />
                <action type="Rewrite" value="/IISApplicationName" />
            </rule>
        </outboundRules>
    </rewrite>
+1

All Articles