2

I'm trying to deploy a WebAPI project to Azure.

It works locally. When I Publish it to Azure, I get 404 on the controller routes.

Looking at the logs, I see the routes are being handled as static files, instead of going through my controllers.

Module IIS Web Core Notification MapRequestHandler Handler StaticFile Error Code 0x80070002 Requested URL http://xxxxx:80/api/studies Physical Path D:\home\site\wwwroot\api\studies Logon Method Anonymous Logon User Anonymous

My Global.asax is:

    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }

And my WebApiConfig.Register is:

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

I've looked at similar questions and tried tweaking my Web.config to no avail. It currently looks like this (relevant part only):

<system.webServer>
    <httpErrors existingResponse="PassThrough"/>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
 </system.webServer>

By the way, I'm on Entity Framework 6 and not using MVC, just straight up WebAPI.

gberger
  • 2,813
  • 3
  • 28
  • 50

3 Answers3

1

Somehow my Global.asax got excluded from the project, so the route mapping never happened.

gberger
  • 2,813
  • 3
  • 28
  • 50
1

I had the same issue. nothing else worked until changing my web config to look like this solved it for me

<handlers>
        <remove name="WebDAV" />
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Samuel
  • 1,295
  • 16
  • 21
0

Have you checked all the necessary Windows Features for your server? Maybe some features are missing from IIS, for example: Internet Information Services - World Wide Web Services - Application Development Features - ASP.NET. You can find and check which features are installed on your machine by going to Windows Features (or going through the Server Manager if you're on a Windows Server).

If that is not your problem, it can sometimes be that ASP.NET is not installed properly. You can re-install ASP.NET by following this article: http://support.microsoft.com/kb/2736284 (it depends on your operating system).

Anders Stensaas
  • 749
  • 5
  • 18
  • 1
    I am using Azure Websites, so it abstracts aways the "Windows Features" thing. I'm pretty sure it automatically configures IIS, ASP.NET etc. – gberger Dec 10 '14 at 20:56
  • It may be some problem with the publish-tool. Can you try deleting all *.dll files in your bin directory, Rebuild and then publish again? You can also check out this similar question: http://stackoverflow.com/questions/13418344/web-api-interface-works-locally-but-gets-404-after-deployed-to-azure-website – Anders Stensaas Dec 10 '14 at 21:02
  • Tried deleting all bin/*.dll, didn't make a difference. – gberger Dec 10 '14 at 21:06
  • Checked all answers to the question you posted, nothing works. – gberger Dec 10 '14 at 21:14