ASP.NET 4.0 URL Routing HTTP Error 404.0 - Not Found


在ASP.NET Web API項目中的路由注冊代碼如下:

public static void RegisterRoutes(RouteCollection routes)
{
     routes.MapHttpRoute(
         name: "DefaultApi",
         routeTemplate: "api/{controller}/{filename}",
         defaults: new { filename = RouteParameter.Optional }
     );
}

當訪問地址突然出現了如下錯誤:

image

解決方法:

1、確認啟用了IIS的 HTTP Redirection

2、在web.config中啟用asp.net 4.0 routing:

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule"/>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <remove name="WebDAVModule" /> </modules>
    <handlers>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
      <remove name="WebDAV" />
    </handlers> 
  </system.webServer>

http://www.matlus.com/rest-apis-put-and-delete-cause-http-error-404/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM