public ActionResult Index()
{
this.Redirect("Not found", 404); //redirect to my error page with code 404
}
答案 0 :(得分:7)
在web.config文件中添加此代码: -
<system.web>
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
在控制器中添加以下代码:
public class ErrorController : Controller{
public ViewResult Index()
{
return View("Error");
}
public ViewResult NotFound()
{
Response.StatusCode = 404; //you may want to set this to 200
return View("NotFound");
}}