【问题标题】:ELMAH: Error Logging Modules And HandlersELMAH:错误记录模块和处理程序
【发布时间】:2015-05-15 16:16:21
【问题描述】:

谁能告诉我,如何在 MVC 5 中使用 Elmah.. 发生错误时,它必须重定向到某个默认页面,例如服务错误,找不到 Http。

public ActionResult About()
{
    ViewBag.Message = "Your app description page.";
    try
    {
        int message = Convert.ToInt32("Hello");
    }
    catch (Exception exp)
    {
        Elmah.ErrorSignal.FromCurrentContext().Raise(exp);
      //  throw;
    }

    return View();
}

如何重定向到错误页面

【问题讨论】:

  • @Bijan 你能看看我做了什么...我如何重定向到特定页面。当我遇到异常时
  • Elmah 是为了 logging 而不是将错误移交给错误页面。查看HandleErrorAttribute 或在Application_Error 方法中的Global.asax.cs 中放置一些东西。

标签: elmah elmah.mvc


【解决方案1】:

如前所述,Elmah 主要用于记录错误。重定向到错误页面不是 Elmah 的责任。要查看记录的错误,请在

处点击 Elmah 处理程序

http://yourDomain.com/elmah.axd

现在,如果你想为异常做重定向,你可以做

  1. 在 web.config 中添加
  2. 在 Global.asax 的 Application_Error 中重定向
  3. 在自定义 HandleErrorAttribute 内重定向(理想情况下,在记录之后)

但是,所有这些都适用于未处理的异常。你的是一个已处理的异常(因为 throw 已被注释)。在这种情况下,您必须直接从 catch 块重定向,例如 return Redirect("/YourErrorPage.htm");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2011-03-01
    • 2012-03-04
    相关资源
    最近更新 更多