1

My Server Program.cs:

WebApplication app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.MapControllers();
app.MapFallbackToFile("index.html");

app.Run();

When calling a non-existing API route, I get a 200 response and then the Json Invalid response:

System.Text.Json.JsonException: '<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

My understanding is that this is because of the line:

app.MapFallbackToFile("index.html");

which causes the server to route to this html page in case of a route not found.

Based on this question, I have tried the various solutions, to no avail.

So, I reverted back to original code above and then just removed the line:

app.MapFallbackToFile("index.html");

However, I am still getting an OK response for an invalid API route, so when I try to read the response content as Json, I'm getting the JsonException still.

What am I doing wrong?

Neil W
  • 7,670
  • 3
  • 28
  • 41
  • 1
    The top voted answer on the other question works for me. Post the exact code you tried. – H H Dec 23 '21 at 14:08
  • @HenkHolterman Thanks for the comment. See me answer ... Grrr! – Neil W Dec 23 '21 at 14:10
  • PS. Whilst my browser cached the HTML response, do you know if I am safe to assume that it would not cache JSON response from the API call so that when results change I won't keep getting a cached JSON response? – Neil W Dec 23 '21 at 14:15

1 Answers1

1

Pfft!

The solutions in the question I linked to DO WORK!

My browser had cached the response for the original api URI, so even after making the changes to the server Program.cs, my request kept returning the cached Index.html response.

Neil W
  • 7,670
  • 3
  • 28
  • 41