ASP.NET MVC Route with values before the controller and no trailing slash

折月煮酒 提交于 2019-11-28 13:56:22

Problem is ASP.net 4.0 doesn't route URLs that ends with an extension to MVC. They do this in order to speed up requests to static files. See this link

What you can do:

1) Configure UrlRoutingModule to route all managed and un-managed requests (default is only route managed requests).

Drawback: May be bad for performance.

<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) Configure to handle .com, .net. org etc extensions

Drawback: Feels like a hack.

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