dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

Blazor webAssembly calling non existing api route returns 200 success with index.html #22083

Closed nssidhu closed 4 years ago

nssidhu commented 4 years ago

using Blazor WebAssembly as hosted solution. When i call an non exisitng route in the api i get back 200 with index.html, expecting that it should returnlt in API error that route does not exisit.

HttpResponseMessage response = await _Http.GetAsync($"api/SomeNonExisitngName/OTPVerification?userName={loggidInUser.Email}&OTP={_OTP}");
        if (response.IsSuccessStatusCode)
        {
}

The actual response returned is, which turns out to be(index.html) 200, success, whereas it is no where what i expect

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>BlazorWebAssembly</title>
    <base href="/" />
    <script src="https://kit.fontawesome.com/xxxxxxxxxxf.js" crossorigin="anonymous"></script>
    <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="css/app.css" rel="stylesheet" />
    <link href="manifest.json" rel="manifest" />
    <link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
    <link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
    <link href="_content/Blazored.Toast/blazored-toast.min.css" rel="stylesheet" />

</head>

<body>
    <app>Loading...</app>

    <div id="blazor-error-ui">
        An unhandled error has occurred.
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>
    <script src="_framework/blazor.webassembly.js"></script>
    <script>navigator.serviceWorker.register('service-worker.js');</script>
</body>
javiercn commented 4 years ago

@nssidhu thanks for contacting us.

That is because Blazor WebAssembly uses a catch-all route to let the client handle non-existing routes and you are likely registering the default fallback route.

I would suggest the following options if you want to get a 404:

ghost commented 4 years ago

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.