ASP.NET Web API not working on Azure

Why does the web API stop working on Azure sites if it runs on localhost.

Error Resource could not be loaded: the server responded with the status 404 (not found) or The resource you are looking for has been deleted, its name has changed or is temporarily unavailable. when pasting url into api in browser.

Note: I have never encountered this error, and I already have several sites already in the azure language, using Web Api attribute routing.

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 showed that this is a common problem:

HTTP 404 Page not found in Web Api hosted in IIS 7.5

WebAPI DELETE request returns 404 error in Azure

Problems with routing WebApi and ASP.NET 4

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

Configure IIS methods for ASP.NET Web APIs on Windows Azure Websites

How ASP.NET v4 URLs Are Handled Without

Getting 404 from WebAPI on Windows Azure Websites

ASP.NET MVC 4 and web API in Azure - HTTP resource not found

MVC 4.5 web API routing not working?

UPDATE

After trying each method suggested in the links above, I deleted everything *. DLL from the solution, created a new MVC + Web API project and added * .dlls to the solution. The building and everyone worked as expected in the first place.

+7
source share
4 answers

Old post, but you tried:

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

Just like @Matija Grcic, after deploying the Web API application on Azure several times, I hit the wall β€œThe resource you were looking for was deleted ..” in new deployments, I found the culprit in mixed problems with versions of the following three assemblies:

System.Net.http.dll

System.Net.Http.Formating.dll

System.Net.Http.WebRequest.dll

I noted that my project link for these assemblies was configured to use them from the global cache, and then was not copied to Azure in the deployment. But I also found that in the error log of my application, he complained that he did not find them. Last hint: they existed in the catalog of my development machine.

I removed them from the development directory and Web.config in any explicit mention of these assemblies from runtime> assemblyBinding> dependAssembly. Published again, and the error prevails.

Then manually copy these three assemblies to the bin folder in Azure using FTP and voila! My web API is working!

I assume that there are new versions in the Azure environment for new web applications (.NET 4.7 at the time of writing this), and my old Visual Studio project can create MVCs and Web APIs that expect to use older versions. Thus, trying to create a new project using and linking to the new .NET framework should help, as @Matija Grcic did.

0
source

I solved the problem by changing from .net Framework 4.6.1 to 4.6.2. Now it works for me

0
source

Make sure you do not have files that were accidentally excluded from your project - especially check for Global.asax and Global.asax.cs. Excluded files are not published and therefore will work locally, but not in Azure.

0
source

All Articles