StatusCodeResult is an ASP.NET Core action result for returning an explicitly selected HTTP status code. For example, setting the status code to 404 produces a raw not-found response. section 15.4.2
The result sends the status code through the middleware pipeline without generating HTML. That behavior suits APIs, where responses are machine-friendly, but often gives Razor Pages users only a generic browser error page. section 15.4.2 section 20.1
Returning a not-found status
An action can return an IActionResult such as StatusCodeResult and explicitly select 404 when a requested product or other resource does not exist. In a web API, returning NotFound() provides the corresponding error response; the [ApiController] attribute can format that response as ProblemDetails. section 15.4.2 section 20.1
Figure 15.4 If you return a raw 404 status code without any HTML, the browser will render a generic default page instead. The message is of limited utility to users and may leave many of them confused or thinking that your web application is broken.
A raw 404 response can cause the browser to display a generic default page instead of a useful application-specific explanation. section 15.4.2
