1

有一个路由表,其中包括

 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 和客户错误页面?

4

1 回答 1

5
public ActionResult PageNotFound(ViewModelBase model)
{
    Response.StatusCode = 404;
    return View(model);
}
于 2012-09-17T17:09:23.970 回答