title: Blazor WebAssembly App - API call from browser - Sorry, there's nothing at this address
body: <p><strong>Update:</strong></p>
  <p>Created an issue on Github ASP.NET Core project:</p>
  <p><a href="https://github.com/dotnet/aspnetcore/issues/32522" rel="nofollow noreferrer">https://github.com/dotnet/aspnetcore/issues/32522</a></p>
  <p><strong>Original:</strong></p>
  <p>Created a new Blazor WebAssembly App with Microsoft Visual Studio 2019 Version 16.9.4 with Target Framework .NET 5.0 and ASP.NET Core Hosted.</p>
  <p>The problem is that if I make an API call from the browser when the site is published to an Azure Web App I get an error response like this:</p>
  <blockquote>
  <p>Sorry, there's nothing at this address.</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/cUgxm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cUgxm.png" alt="enter image description here" /></a></p>
  <p>If I make the request with &quot;Empty cache and hard reload&quot; everything works as expected.</p>
  <p><a href="https://i.stack.imgur.com/GhMH0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GhMH0.png" alt="enter image description here" /></a></p>
  <p>The request always work on <code>localhost</code>.</p>
  <p>It is not limited to images loaded via API, same result for <code>JSON response</code>.</p>
  <p><a href="https://i.stack.imgur.com/CF3vL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CF3vL.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/iIjbB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iIjbB.png" alt="enter image description here" /></a></p>
  <p>How can I tell <code>Blazor</code> to not use/ignore routing for URLs that contains <code>/api/</code>?</p>
  <p>I have read about <code>ASP.NET Core Blazor routing</code> but not found anything there.</p>
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0</a></p>
  <p>The error message is from the <code>App.razor</code> file:</p>
  <pre><code>&lt;CascadingAuthenticationState&gt;
      &lt;Router AppAssembly=&quot;@typeof(Program).Assembly&quot; PreferExactMatches=&quot;@true&quot;&gt;
          &lt;Found Context=&quot;routeData&quot;&gt;
              &lt;RouteView RouteData=&quot;@routeData&quot; DefaultLayout=&quot;@typeof(MainLayout)&quot; /&gt;
          &lt;/Found&gt;
          &lt;NotFound&gt;
              &lt;LayoutView Layout=&quot;@typeof(MainLayout)&quot;&gt;
                  &lt;p&gt;Sorry, there's nothing at this address.&lt;/p&gt;
              &lt;/LayoutView&gt;
          &lt;/NotFound&gt;
      &lt;/Router&gt;
  &lt;/CascadingAuthenticationState&gt;
  &lt;MatPortalHost&gt;&lt;/MatPortalHost&gt;
  </code></pre>
  <p>Same result if I use default value in <code>App.razor</code>:</p>
  <pre><code>&lt;Found Context=&quot;routeData&quot;&gt;
      &lt;AuthorizeRouteView RouteData=&quot;@routeData&quot; DefaultLayout=&quot;@typeof(MainLayout)&quot;&gt;
          &lt;NotAuthorized&gt;
              @if (!context.User.Identity.IsAuthenticated)
              {
                  &lt;RedirectToLogin /&gt;
              }
              else
              {
                  &lt;p&gt;You are not authorized to access this resource.&lt;/p&gt;
              }
          &lt;/NotAuthorized&gt;
      &lt;/AuthorizeRouteView&gt;
  &lt;/Found&gt;
  </code></pre>
  <p>ImagesController:</p>
  <pre><code>[Route(&quot;api/[controller]&quot;)]
  [ApiController]
  [Authorize]
  public class ImagesController : ControllerBase
  {
      private readonly ApplicationDbContext _context;
  
      public ImagesController(ApplicationDbContext context)
      {
          _context = context;
      }
  
      [HttpGet(&quot;{id}/file&quot;)]
      [AllowAnonymous]
      public async Task&lt;ActionResult&gt; GetImageDataFile(int id)
      {
          var image = await _context.Images.FindAsync(id);
  
          if (image == null)
          {
              return NotFound();
          }
  
          return File(image.Data, image.ContentType);
      }
  </code></pre>
  <p><code>Program.cs</code> for <code>Blazor.Client</code>:</p>
  <pre><code>namespace Blazor.Client
  {
      public class Program
      {
          public static async Task Main(string[] args)
          {
              var builder = WebAssemblyHostBuilder.CreateDefault(args);
              builder.RootComponents.Add&lt;App&gt;(&quot;#app&quot;);
  
              builder.Services.AddHttpClient(&quot;Blazor.ServerAPI&quot;, client =&gt; client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
                  .AddHttpMessageHandler&lt;BaseAddressAuthorizationMessageHandler&gt;();
  
              builder.Services.AddHttpClient&lt;ImagesHttpClient&gt;(client =&gt;
                  client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
                  .AddHttpMessageHandler&lt;BaseAddressAuthorizationMessageHandler&gt;();
  
              builder.Services.AddHttpClient&lt;PostsAnonymousHttpClient&gt;(client =&gt;
                  client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress));
  
              // Supply HttpClient instances that include access tokens when making requests to the server project
              builder.Services.AddScoped(sp =&gt; sp.GetRequiredService&lt;IHttpClientFactory&gt;().CreateClient(&quot;Blazor.ServerAPI&quot;));
  
              builder.Services.AddApiAuthorization();
  
              builder.Services.AddMatBlazor();
  
              await builder.Build().RunAsync();
          }
      }
  }
  </code></pre>
  <p><code>Startup.cs</code> for <code>Blazor.Server</code>, not modified at all:</p>
  <pre><code>namespace Blazor.Server
  {
      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.
          // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                  options.UseSqlServer(
                      Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  
              services.AddDatabaseDeveloperPageExceptionFilter();
  
              services.AddDefaultIdentity&lt;ApplicationUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = true)
                  .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
              services.AddIdentityServer()
                  .AddApiAuthorization&lt;ApplicationUser, ApplicationDbContext&gt;();
  
              services.AddAuthentication()
                  .AddIdentityServerJwt();
  
              services.AddControllersWithViews();
              services.AddRazorPages();
          }
  
          // 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.UseMigrationsEndPoint();
                  app.UseWebAssemblyDebugging();
              }
              else
              {
                  app.UseExceptionHandler(&quot;/Error&quot;);
                  // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                  app.UseHsts();
              }
  
              app.UseHttpsRedirection();
              app.UseBlazorFrameworkFiles();
              app.UseStaticFiles();
  
              app.UseRouting();
  
              app.UseIdentityServer();
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapRazorPages();
                  endpoints.MapControllers();
                  endpoints.MapFallbackToFile(&quot;index.html&quot;);
              });
          }
      }
  }
  </code></pre>
  <p>Publish config looks like this:</p>
  <p><a href="https://i.stack.imgur.com/owNv3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/owNv3.png" alt="enter image description here" /></a></p>