网页配置
<customErrors mode="On" defaultRedirect="~/Error/HttpError"> // is not working
<error redirect="~/Error/NotFound" statusCode="404" />
<error redirect="~/Error/HttpError" statusCode="500" /> // also it is not working
</customErrors>
错误控制器
public class ErrorController : Controller
{
//
// GET: /Error/
public ActionResult HttpError()
{
return Content("HttpError was called!");
//return View("Error");
}
public ActionResult NotFound(string aspxerrorpath)
{
return View();
}
public ActionResult Index()
{
return RedirectToAction("Index", "Home");
}
}
对于 404 错误,它也会调用 NotFound 操作,但对于其他错误,它从未命中 HttpError 方法。
public ActionResult ETest()
{
throw new Exception("yahoo");
}
我运行上面的测试代码,直接进入Error.cshtml页面。
我做错了什么?