當我在 Asp.Net Core API 專案中回傳 404 狀態代碼時。它適用于 chrome,但在 mozilla firefox 中顯示空白頁面而不是 404 錯誤頁面,就像在其他瀏覽器中一樣。
我的 API 的示例代碼如下:
[HttpGet]
[Route("OpenBlobFile", Name = "url")]
public async Task<ActionResult> OpenBlobFile(string fileName, string folder)
{
return new NotFoundObjectResult(null);
}
在此處輸入圖片說明
uj5u.com熱心網友回復:
我從這里得到答案:https : //forums.asp.net/t/1384390.aspx?Returning 404 from controller displays empty page in firefox
結論:Firefox 沒有像其他瀏覽器那樣的原生錯誤頁面。
uj5u.com熱心網友回復:
如果您只想要 404 錯誤,則需要使用這些
return StatusCode(404);
return new StatusCodeResult(404);
其中任何一個都不會,因為它們會將 id 或物件添加到回應的正文中
return StatusCode(404, 123);
return StatusCode(404, new { id = 123 });
return new NotFoundObjectResult(123);
uj5u.com熱心網友回復:
是的。Chrome 和 IE 表現正常并顯示相應的默認錯誤頁面,而 Firefox 認為最好顯示空白頁面。
因此,在大多數情況下,Firefox 不會顯示通用的 404 錯誤頁面。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/349258.html
