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!

0

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

3 Comments

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
Hi, did you handle error on Application_Error on Global.asax.cs?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.