Unable to redirect to error page in MVC

332 Views Asked by At

I tried to redirect to error page on error. but it does not work.

It just giving - Uh-oh, something went wrong! Error Code: 500 message on browser instead of redirecting to error page. error page is already existed in shared folder.

Below is the code in controller:

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

web config has included below line:

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

did google but, it shows above stuff and it should work but still not work.

Using MVC 4 basic template.

Please guide.

thanks

1

There are 1 best solutions below

2
meda On

Errors can occur in the error view itself. In that case, the default ASP.NET error page is displayed. To avoid this, you can configure the application to display an error file in the customErrors section of the Web.config file, as shown in the following example:

<system.web>
  <customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
    <error statusCode="500" redirect="/Error.htm" />
  </customErrors>
</system.web>