I would like to serve a user friendly "not found" page in my ASP.NET MVC application while providing a 404 status code. (based on this answer)

我已经有了机制来捕获无效路由,并且我的ErrorController/Handle404操作提供了自定义404页面。

我当前的Handle404实现:

    public ActionResult Handle404()
    {
        Response.StatusCode = 404;
        return View("NotFound");
    }

当前,IIS将页面用作404 - File or directory not found.The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.(标准IIS页面,而不是我的用户友好内容)

在仍提供内容的同时,如何在Handle404操作提供的结果中包含404状态代码?

最佳答案

环境

 Response.TrySkipIisCustomErrors = true;

做到了。

关于c# - ASP.NET MVC : How to serve content while returning status code 404? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2547582/

10-09 18:15