8

Why would Web API stop working on Azure Websites if it works on localhost.

The error is Failed to load resource: the server responded with a status of 404 (Not Found) or The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. when pasting URL to api in browser.

NOTE: I have never encountered this error and I already have several sites already on azure 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 revealed that this is a common problem:

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

After trying every method suggested in the links above i've removed all the *.dlls from the solution, created a new MVC+Web API project and added *.dlls to the solution. Build and everything worked as expected in the first place.

4
  • What is the URL you're trying to access? Commented Dec 18, 2013 at 22:40
  • You should enable CORS too. Commented Dec 19, 2013 at 9:40
  • @ThiagoCustodio no need for CORS here. Commented Dec 19, 2013 at 11:47
  • I have the some problem but only on some methods on some controllers. Very strange thing Commented Jul 10, 2017 at 20:55

5 Answers 5

2

Have you tried this setting?

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Sign up to request clarification or add additional context in comments.

Comments

1

Try the below 2 methods.

Method 1. try Setting the web.config as below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
  <remove name="aspNetCore"/>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
  <aspNetCore processPath="dotnet" arguments=".\Somerandomname.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>

For more details, you could refer ASP.NET Core Web API runs locally but not on Azure app service.

Method 2. Make sure your url in the browser is correct. In some occations you need to add

azureAPIurl/api/controllername

Comments

0

The same than @Matija Grcic, after deploying successfully a Web API application on Azure many times, I hit the wall of "The resource you are looking for has been removed.." in new deployments. I found the culprit in mixed versioning problems from the next three assemblies:

System.Net.Http.dll

System.Net.Http.Formating.dll

System.Net.Http.WebRequest.dll

I noted that my project reference to those assemblies was set to use them from global cache, and then were not copied to Azure in the deployment. But also I found that in the error Log of my application, it was complaining of not found them. Last clue: they existed in directory of my development machine.

I removed them of the development directory and Web.config any explicit mention of those assemblies from the section runtime>assemblyBinding>dependentAssembly. Published again and the error prevailed.

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

I guess that there are new versions in the environment of Azure for new Web Apps (.Net 4.7 in the moment of write this) and my old Visual Studio project may been building MVC and Web API expecting to use the old versions. In that way, trying to create a new project using and referencing a newer .Net framework must help, like @Matija Grcic did it.

Comments

0

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

Comments

0

Make sure that you don't have any files that are accidentally excluded from your project - specifically check for Global.asax and Global.asax.cs. Excluded files don't get published, and therefore, would work locally but not on Azure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.