0

Web.config

<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ページに直接移動します。

私が間違っていることは何ですか?

4

1 に答える 1

0

FilterConfigs.csにこれがありますか?

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
}

デフォルトのエラーを処理するには、HandleError属性が必要です。

于 2013-03-09T18:00:50.447 に答える