0
的Web.configAsp.net MVC4,defaultRedirect不工作?
<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页面。
我做错了什么?
是的,我有。但HttpError从未被调用。 – 2013-03-11 14:47:54
@Expertwannabe - 你正在做一个远程连接,对吗?在本地计算机上调用时没有看到错误处理程序。 – 2013-03-11 16:59:54
@谢谢你的关心,我在本地机器上试过了,但它不起作用。我可以使用Application_error而不是CustomErrors来解决这个问题。 – 2013-03-11 20:18:50