0

I have set up a general error page where I want the user directed whenever something somewhere throws a wobbly. However I can't seem to get the user directed to the error page when they try to access a restricted path - such as App_Data. Instead they see an unfriendly: HTTP Error 404.8 - Not Found bla bla bla..

My webconfig:

<customErrors mode="On" defaultRedirect="~/Home/RenderError">
</customErrors>

I have also tried this:

<customErrors mode="On" defaultRedirect="~/Home/RenderError">
  <error statusCode="404" redirect="~/Home/RenderError" />
</customErrors>

Any idea? Thank you!

DeanR
  • 370
  • 2
  • 13

1 Answers1

1

I think that you should define an Error controller for handle custom errors. It looks like

public class ErrorController : Controller
{
  public ViewResult Index()// It is used for **defaultRedirect**
  {
    return View("Error");
  }
  public ViewResult Error404()
  {
    Response.StatusCode = 404;  
    return View("Error404");// Not found
  }
  public ViewResult Error403()
  {
    Response.StatusCode = 403; 
    return View("UnauthorizedAccess");
  }

}

And your view as

<customErrors mode="On" defaultRedirect="~/Error">
   <error redirect="~/Error/Error404" statusCode="404" />
   <error redirect="~/Error/UnauthorizedAccess" statusCode="403" />
</customErrors>

Hope it helps!

Lewis Hai
  • 1,114
  • 10
  • 22
  • Hi, thanks for the response! However I don't think this will fix my issue as the end result is the same - it doesn't catch the 404.8 error – DeanR Dec 22 '15 at 03:14
  • Hi, did you handle error on Application_Error on Global.asax.cs? – Lewis Hai Dec 22 '15 at 03:29
  • It may help you http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4 – Lewis Hai Dec 22 '15 at 03:30