Home > Mobile >  Asp.Net returning 404 status code, displays empty / blank page in mozilla firefox
Asp.Net returning 404 status code, displays empty / blank page in mozilla firefox

Time:11-05

When I an returning 404 status code in Asp.Net Core API project. It works fine with chrome but, shows blank page in mozilla firefox instead of 404 error page, like in other browsers.

Sample Code for my API is below:

[HttpGet]
[Route("OpenBlobFile", Name = "url")]
public async Task<ActionResult> OpenBlobFile(string fileName, string folder)
{
    return new NotFoundObjectResult(null);
}

enter image description here

CodePudding user response:

I got my answer from here: https://forums.asp.net/t/1384390.aspx?Returning 404 from controller displays empty page in firefox

Conclusion: Firefox does not have a native error page, like in other browsers.

CodePudding user response:

You need to use these if you want just a 404 error

 return StatusCode(404);
 return new StatusCodeResult(404);

Any of these won't, as they add either the id or an object to the response's body

 return StatusCode(404, 123);
 return StatusCode(404, new { id = 123 });
 return new NotFoundObjectResult(123);

CodePudding user response:

Yes. Chrome and IE behave normally and display the corresponding default error page, while Firefox believes it is best to display a blank page.

Therefore, in most cases, Firefox will not display a generic 404 error page.

  • Related