0

I have mvc 3 application which when a Standard generic throw new Exception is thrown in code the error page from Views\Shared\error.cshtml is shown. This is done by simply setting <customErrors mode="On"/>. (This is As expected and as Desired)

The application is using WCF services in middle tier which when these services generate FaultException MVC is not showing up the error page it is showing details of the web service call to the user on screen. All I want to do is handle the error in my code and show the user the Error.cshtml. I have tried changing global asax but this dosent work.

   protected void Application_Error(object sender, EventArgs e)
    {
      Exception exception = Server.GetLastError();
      if (exception.GetType() == typeof(FaultException))
      {
        throw new Exception("There was a fault exception that i do not want to show details of to user.");

      }
    }
tereško
  • 58,060
  • 25
  • 98
  • 150
Somedeveloper
  • 817
  • 2
  • 14
  • 31

2 Answers2

0

Try creating an ErrorController as asp.net MVC will try to resolve the link you specified in the web.config as {Controller}/{View} unless you specify it to ignore that page. Also, you may want to apply an attribute to handle exceptions instead.

Ann B. G.
  • 304
  • 2
  • 6
0

You can also create a error controller/view and in your catch block redirect to the custom error page of your choosing

    try
    {
        foo.bar()      
    }
    catch(SpecificException)
    {
       RedirectToAction("500", "Error");
    }
Justen Martin
  • 626
  • 1
  • 6
  • 13