You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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.cs to 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 UrlRoutingModule entry 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 like Web.Debug.config or Web.Release.config might 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 .vs folder, and sometimes the bin/obj directories get corrupted. Additionally, if your local .csproj file 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.cs and check that the default route (or the route for your startup page) is correctly defined. For example, the standard default route looks like this:
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
    Also, confirm your project’s startup URL is set correctly (right-click project → Properties → Web → Startup URL).
  • 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 .vs folder (hidden in your project root), then delete the bin and obj directories. 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 .csproj file 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:50:39