ASP.NET MVC项目启动遇404错误:资源无法找到问题求助
Hey there! Let’s dig into that "Resource Cannot Be Found" 404 error you hit when launching your ASP.NET MVC project, and go over the likely root causes plus actionable fixes based on your experience of resolving it by re-downloading from TFS.
Root Causes of the 404 Error
Since re-syncing from TFS fixed the issue, the problem was almost certainly tied to local configuration mismatches or corrupted files. Here are the most common culprits:
- Broken Routing Configuration: ASP.NET MVC relies on the rules in
App_Start/RouteConfig.csto map URLs to controllers and actions. If this file was locally modified (e.g., default route changed, or a route for your startup page was removed), or if web.config had settings that interfered with routing (like incorrect module registrations), the server couldn’t find the resource matching your startup URL. - Corrupted or Modified Web.config: The web.config file controls critical project settings—from compilation rules to authorization and URL handling. If you accidentally edited this file (e.g., deleted the
UrlRoutingModuleentry in<system.webServer>/<modules>, messed up custom error settings, or added conflicting rewrite rules), it could prevent the project from resolving the startup page. Local transformation files likeWeb.Debug.configorWeb.Release.configmight also have had invalid transforms that broke the final config when compiling. - Local Cache or Project File Issues: Visual Studio stores temporary cache in the hidden
.vsfolder, and sometimes thebin/objdirectories get corrupted. Additionally, if your local.csprojfile was missing references to controllers or view files (maybe from accidental deletions), the project wouldn’t compile those resources, leading to a 404 when trying to access them.
Troubleshooting & Fixes
If you run into this again without wanting to re-download the entire project, try these steps:
- Verify Routing Rules: Open
App_Start/RouteConfig.csand check that the default route (or the route for your startup page) is correctly defined. For example, the standard default route looks like this:
Also, confirm your project’s startup URL is set correctly (right-click project → Properties → Web → Startup URL).routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); - Compare Web.config with TFS: Use TFS’s compare feature to check if your local web.config differs from the repository version. Look for changes to routing modules, authorization rules, or custom error settings. Fix any mismatches, and double-check that transformation files don’t have invalid XML or conflicting settings.
- Clean Local Cache & Build: Delete the
.vsfolder (hidden in your project root), then delete thebinandobjdirectories. Rebuild the project from scratch—this clears out any corrupted temporary files that might be causing configuration issues. - Test Direct URL Access: Instead of relying on the default startup page, manually type the full URL (e.g.,
http://localhost:5000/Home/Index) into your browser. If this works, the issue is likely with your startup page setting rather than routing itself. - Check Project File References: Open your
.csprojfile and ensure all controller and view files are included. If any are marked as "missing" or excluded, restore them from TFS or re-add them to the project.
内容的提问来源于stack exchange,提问作者user1250264
相关产品推荐
相关产品推荐

