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?