ASP.NET Core MVC 404 Pages: Custom Routes Without Breaking Static Files

Published 01/10/2026

Description

How should an ASP.NET Core MVC application handle a 404 Not Found response? Contents: 0:00 - Introduction 0:11 - Description 1:08 - Initial Website 3:07 - Tuned 404 Page 5:44 - Resources / Actions Split 9:08 - Conclusion A missing application URL and a missing static resource are both technically 404 errors, but they should not necessarily receive the same response. When a visitor enters an invalid URL or follows an outdated internal link, a custom 404 page gives them a better experience. It can explain that the page does not exist and guide them back to useful content. But when a browser requests a missing image, CSS file, JavaScript file, font, or library asset, returning a complete branded HTML error page is usually unnecessary. It adds extra processing and can make debugging missing static resources less clear. In this video, I show how to handle both cases in ASP.NET Core MVC: Start with the default ASP.NET Core MVC 404 behaviour Create a dedicated error controller and error views Use UseStatusCodePagesWithReExecute Return a custom 404 page for missing MVC routes Understand why the same middleware also catches missing static files Retrieve the original requested path with IStatusCodeReExecuteFeature Identify static-resource requests by extension and directory Return a clean, empty 404 response for missing resources Keep a useful branded error page for real user-facing URLs The result is a more polished ASP.NET Core MVC application: users see a helpful custom page when they reach an invalid URL, while missing static files remain normal lightweight 404 responses. This approach is useful for developers building MVC websites that need clean error handling, better usability, and predictable responses for browsers, crawlers, and diagnostics. #ASPNETCore #DotNet #WebDevelopment Follow me on X: https://l.samayas.eu/jo3eaYEf3E?P=YT&V=155 Buy me a Coffee : https://l.samayas.eu/jX6xL7EWhd?P=YT&V=155 Studio Equipme