有一个包含
的路由表 routes.MapRoute("404-PageNotFound", "{*url}", new { controller = "Error", action = "PageNotFound" });
web.config有:
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="/Error/PageNotFound" />
</customErrors>
当没有路由匹配并且使用以下方式呈现错误视图时,ErrorController会被命中:
public ActionResult PageNotFound(ViewModelBase model)
{
return View(model);
}
响应的状态代码为200,但在这种情况下需要404。有没有办法返回http代码404和客户错误?
答案 0 :(得分:5)
public ActionResult PageNotFound(ViewModelBase model)
{
Response.StatusCode = 404;
return View(model);
}