title: ASP.NET MVC 5 - (HTTP Error 404.0 - Not Found) with long non-existing URL
body: <p>I created a new project in Microsoft Visual Studio Express 2013 for Web.
  It is an ASP.NET MVC 5 - .NET Framework 4.5 project.</p>
  
  <p>I wanted to handle (The resource cannot be found):</p>
  
  <p><img src="https://i.stack.imgur.com/YVHe0.jpg" alt="The resource cannot be found"></p>
  
  <p>I did handle it using the code below.</p>
  
  <p>This code will work if I do something like (/Home/kddiede/ddiij) or (/djdied/djie/djs), this will result in showing my custom Error page.</p>
  
  <p>However, when I try to do something like (/Home/kddiede/ddiij/dfd/sdfds/dsf/dsfds/fd), or any long non-existing URL, It will show me this:</p>
  
  <p><img src="https://i.stack.imgur.com/2GIrX.jpg" alt="HTTP Error 404.0 - Not Found"></p>
  
  <p>Code from: <a href="http://www.codeproject.com/Articles/635324/Another-set-of-ASP-NET-MVC-4-tips" rel="noreferrer">http://www.codeproject.com/Articles/635324/Another-set-of-ASP-NET-MVC-4-tips</a></p>
  
  <p>Tip 16: Customizing error screens</p>
  
  <p>Error Page is in the /View/Shared/Error.cshtml</p>
  
  <p>Web.config</p>
  
  <pre><code>&lt;system.web&gt;
  &lt;customErrors mode="RemoteOnly" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>Global.asax</p>
  
  <pre><code>protected void Application_EndRequest(Object sender, EventArgs e)
  {
      ErrorConfig.Handle(Context);
  }
  </code></pre>
  
  <p>ErrorConfig Class</p>
  
  <pre><code>public class ErrorConfig
  {
    public static void Handle(HttpContext context)
    {
      switch (context.Response.StatusCode)
      {
        //Not authorized
        case 401:
          Show(context, 401);
          break;
  
        //Not found
        case 404:
          Show(context, 404);
          break;
      }
    }
  
    static void Show(HttpContext context, Int32 code)
    {
      context.Response.Clear();
  
      var w = new HttpContextWrapper(context);
      var c = new ErrorController() as IController;
      var rd = new RouteData();
  
      rd.Values["controller"] = "Error";
      rd.Values["action"] = "Index";
      rd.Values["id"] = code.ToString();
  
      c.Execute(new RequestContext(w, rd));   
    }
  }
  </code></pre>
  
  <p>ErrorController</p>
  
  <pre><code>internal class ErrorController : Controller
  {
    [HttpGet]
    public ViewResult Index(Int32? id)
    {
      var statusCode = id.HasValue ? id.Value : 500;
      var error = new HandleErrorInfo(new Exception("An exception with error " + statusCode + " occurred!"), "Error", "Index");
      return View("Error", error);
    }
  }
  </code></pre>
  
  <p>This last bit of code from the website I mentioned above was not added in Global.asax because It is already in FilterConfig.cs</p>
  
  <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
    filters.Add(new HandleErrorAttribute());
  }
  </code></pre>
  
  <p>Anyone knows how to fix it?</p>
  
  <p>Thanks in advance.</p>