2013-12-18 70 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来解决此问题。 现在它适用于我

相关问题