2013-12-18 72 views
6

如果Web API在本地主機上工作,它將停止在Azure網站上工作。ASP.NET Web API無法在Azure上工作

的錯誤是無法加載資源:服務器與404(未找到)狀態迴應您正在尋找已被刪除的資源,有其名稱更改,或者暫時不可用。在瀏覽器中將URL粘貼到api時的

注意: 我從來沒有遇到過這個錯誤,並且我已經有幾個站點已經使用Web Api屬性路由的Azure。

WebConfig

public static void Register(HttpConfiguration config) 
     { 

      config.MapHttpAttributeRoutes(); 

      config.Routes.MapHttpRoute(
       name: "DefaultApi", 
       routeTemplate: "api/{controller}/{id}", 
       defaults: new { id = RouteParameter.Optional } 
      ); 
} 

RouteConfig

public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 


      routes.MapRoute(
      name: "Cities", 
      url: "Cities/{id}/{name}/{action}", 
      defaults: new { controller = "Cities", action = "Index" } 
      ); 

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

的Global.asax

AreaRegistration.RegisterAllAreas(); 
      GlobalConfiguration.Configure(WebApiConfig.Register); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 

      RouteConfig.RegisterRoutes(RouteTable.Routes); 
      BundleConfig.RegisterBundles(BundleTable.Bundles); 

Goggling透露,這是一個常見的問題:

HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

WebAPI DELETE request return 404 error in Azure

WebApi and ASP.NET 4 routing issues

https://stackoverflow.com/questions/15805471/using-windows-azure-websites-with-extensionlessurlhandler

Configuring IIS methods for ASP.NET Web API on Windows Azure Websites

How Extensionless URLs Are Handled By ASP.NET v4

Getting 404 from WebAPI on Windows Azure Web Sites

ASP.NET MVC 4 and Web API in Azure - No HTTP resource was found

MVC 4.5 Web API Routing not working?

UPDATE

嘗試後每一個方法在上面我已經刪除了所有* .DLL文件從溶液中的鏈接提示,創造了一個新的MVC + Web API項目並將* .dlls添加到解決方案。建設和一切按照預期工作在第一位。

+0

什麼是您試圖訪問的URL? – pollirrata

+0

您應該啓用CORS。 –

+0

@ThiagoCustodio這裏不需要CORS。 –

回答

2

老帖子,但你有沒有嘗試過:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
</system.webServer> 
+0

舊的迴應,但對我來說新問題。非常感謝張貼,只是挽救了我的最後一縷頭髮。幫助我將asp.net身份集成到現有的webApi中。所有在我的本地機器上運行良好 – CF5

0

比@Matija葛契奇同樣,成功地部署在Azure上無數次的Web API應用程序後,我打的牆「的資源你正在尋找已被刪除..「在新的部署。我發現混合版本問題的罪魁禍首來自接下來的三個程序集:

System.Net.Http。DLL

System.Net.Http.Formating.dll

System.Net.Http.WebRequest.dll

我注意到,我的項目引用這些組件設置爲從全局高速緩存使用它們,然後在部署中未複製到Azure。但是我也發現在我的應用程序的錯誤日誌中,它抱怨沒有找到它們。最後一條線索:它們存在於我的開發機器的目錄中。

我將它們從開發目錄和Web.config中移除,並從section> runtime> assemblyBinding> dependentAssembly中明確提及這些程序集。再次發佈並且錯誤佔上風。

然後使用FTP和瞧手動將引用的三個程序集複製到Azure中的bin文件夾!我的Web API正在運行!

我猜Azure的環境中有新版本用於新的Web Apps(在寫這篇文章的時候.Net 4.7),而我的舊Visual Studio項目可能正在構建MVC和Web API,希望使用舊版本。通過這種方式,嘗試使用和引用更新的.Net框架來創建新項目必須有所幫助,就像@Matija Grcic所做的那樣。

0

我已經通過將.net Framework 4.6.1更改爲4.6.2來解決此問題。 現在它適用於我

相關問題