title: 404 Not Found when Calling Deployed ASP.Net Core Web API
body: <p>We're having a devil of a time figuring out why our Web API endpoint can't be called in production (Azure web app service), but works fine running locally. We get 404 when calling our deployed API endpoint.</p>
  <p>Sample local URL that works in Postman:
  <code>https://localhost:44370/api/Foo/Bar</code></p>
  <p>Sample prod URL that returns 404 every time:
  <code>https://fooapi.azurewebsites.net/api/Foo/Bar</code></p>
  <p>(Real routes replaced for brevity/privacy).</p>
  <p>We have no <code>web.config</code> file and no <code>appsettings.json</code> either locally or in the deployed build.</p>
  <p><code>Program</code> and <code>Startup</code> are boilerplate, modeled after the default Web API template.</p>
  <p><code>Program.cs</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Hosting;
  
  namespace FooAPI
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateHostBuilder(args).Build().Run();
          }
  
  
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                  });
      }
  }
  
  </code></pre>
  <p><code>Startup.cs</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  
  namespace FooAPI
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddApplicationInsightsTelemetry();
  
              services.AddControllers();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseHsts();
  
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  }
  </code></pre>
  <p><code>FooController.cs</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.AspNetCore.Mvc;
  using FooAPI.Models;
  using System.Net;
  using System.Threading.Tasks;
  using System.IO;
  using System.Text;
  using System;
  
  namespace FooAPI.Controllers
  {
      [ApiController]
      [Route(&quot;api/[controller]/[action]&quot;)]
      public class FooController : ControllerBase
      {
  
          public async Task&lt;ActionResult&gt; Bar()
          {
             return new OkObjectResult(&quot;Not our real implementation obv.&quot;);
          }
  
      }
  }
  </code></pre>
  <p>Project file:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp3.1&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.ApplicationInsights.AspNetCore&quot; Version=&quot;2.18.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Newtonsoft.Json&quot; Version=&quot;11.0.2&quot; /&gt;
    &lt;/ItemGroup&gt;
  
  
  &lt;/Project&gt;
  
  </code></pre>
  <p>We have already:</p>
  <ul>
  <li>Tried the suggestions in <a href="https://stackoverflow.com/questions/55012289/azure-endpoint-reached-but-calls-to-api-returning-404-error/62970620#62970620">this answer</a>.</li>
  <li>Created a new app service in Azure and deployed into that.</li>
  <li>Confirmed that the site actually contains our application files (Foo dlls etc from the build)</li>
  <li>Connected App Insights (no insights provided)</li>
  <li>Browsed to API root; it has the default &quot;A web app service is running here yay&quot; page. But the actual API endpoint is not found.</li>
  </ul>