ASP.NET MVC Route with values ​​in front of the controller and without a slash

This is probably a simple question, but I just can't get it to work.

I have this route specified in my RouteConfig

routes.MapRoute(
    name: "DefaultSiteRoute",
    url: "{accountid}/{hostname}/{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, accountid = UrlParameter.Optional, hostname = UrlParameter.Optional  }
);

And it works great for a url like this

/123456/www.test.com/

or

/123456/www.test.com/Controller/Action

but he can't handle it

/123456/www.test.com

I get IIS 404

What's more strange, if I call Url.Actionfor this route using the default controller and action (i.e. Home / Index), it creates a URL without a trailing slash, which it then doesn't recognize. I really need it to work with and without backside.

+4
1

, ASP.net 4.0 URL-, MVC. . .

:

1) UrlRoutingModule ( ).

: .

<system.webServer>
    <modules>
     <remove name ="UrlRoutingModule-4.0"/>
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="runtimeVersionv4.0" />
    </modules>
<system.webServer>

2) .com,.net. org ..

: .

   <system.webServer>
       <handlers>
          <add name="UrlRoutingHandler"
           type="System.Web.Routing.UrlRoutingHandler, 
                 System.Web, Version=4.0.0.0, 
                 Culture=neutral, 
                 PublicKeyToken=b03f5f7f11d50a3a"
                 path="*.com"
                 verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"/>
+6

All Articles