My solution is 2 steps.
I initially solved this problem by adding this function to the Global.asax.cs file:
protected void Application_Error(Object sender, EventArgs e)
Where I tried casting Server.GetLastError () to an HttpException and then checked GetHttpCode. This solution is described in detail here:
ASP.NET MVC Custom Error Handling Application_Error Global.asax?
This is not the original source where I received the code. However, this only catches 404 errors that have already been redirected. In my case, this means any level 2 URL.
for example, these URLs displayed page 404:
www.site.com/blah
www.site.com/blah/blah
however, www.site.com/blah/blah/blah will simply say that the page was not found. Adding your track along the entire route AFTER all my other routes resolved this:
routes.MapRoute( "NotFound", "{*url}", new { controller = "Errors", action = "Http404" } );
However, the NotFound route does not seem to route requests that have file extensions. This works when they are captured by different routes.
Marcus10110 Feb 02 2018-12-12T00: 00Z
source share