0

我试图在错误时重定向到错误页面。但它不起作用。

它只是Uh-oh, something went wrong! Error Code: 500在浏览器上提供 - 消息,而不是重定向到错误页面。错误页面已存在于共享文件夹中。

以下是控制器中的代码:

  [HandleError(View = "Error")]
    public ActionResult Index()
    {
        int u = Convert.ToInt32("");// Error line
        return View();
    }

网络配置包括以下行:

      <customErrors mode="On" defaultRedirect="Error"></customErrors>

谷歌但是,它显示了上面的东西,它应该可以工作,但仍然不能工作。

使用 MVC 4 基本模板。

请指导。

谢谢

4

1 回答 1

1

错误视图本身可能会出现错误。在这种情况下,将显示默认的 ASP.NET 错误页面。customErrors为避免这种情况,您可以将应用程序配置为在文件部分显示错误文件Web.config,如以下示例所示:

<system.web>
  <customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
    <error statusCode="500" redirect="/Error.htm" />
  </customErrors>
</system.web>
于 2014-11-02T17:03:29.327 回答