Missing error page in SPA project templates
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Description
When **not** in development environment, exceptions in controllers produce an HTTP 200 with the `index.html` as content.
The error page in SPA project isn't working since ASP.NET Core 3.x. The page is in the template, but the Razor pages aren't loaded unless you choose to enable the individual auth or do it manually. It was previously working because Razor pages was loaded through `AddMvc()`, but since 3.x, the template only use `AddControllersWithViews()`.
The problem is not visible in Development environment, which use the `UseDeveloperExceptionPage()`, but only for `UseExceptionHandler("/Error")`, because the route doesn't exists, then the default route fallback provided by `UseSpa` takes over and returns an HTTP 200 with the default page as content.
### To Reproduce
`dotnet new react`
edit `WeatherForecastController.cs` and throw an exception in the `Get()` method
`dotnet run` then go the the "Fetch data" page
you should see the HTTP 500 request in your browser debugger for `https://localhost:5001/weatherforecast`
`dotnet publish` to build the react project
edit `launchSettings.json` and set `Production` as environment
`dotnet run` then go the the "Fetch data" page
you should see the HTTP 200 request in your browser debugger for `https://localhost:5001/weatherforecast`
### Proposals
Remove the `#if (IndividualLocalAuth)` statements in `src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs` around `services.AddRazorPages();` and `endpoints.MapRazorPages();`
Or
Remove the error page and `app.UseExceptionHandler("/Error");`. I don't find this page relevant for the SPA templates, the errors must be handled by the SPA itself.
### Further technical details
- ASP.NET Core 3.1
Contributor guide
Assessment
This issue has not been assessed yet.