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

生产环境下ASP.Net MVC路由URL返回404,是否需额外配置?

Troubleshooting ASP.NET MVC 404 Errors After Deployment

Hey there! It sounds like your static content is serving just fine (since index.html loads without issue), but the MVC routing system isn't kicking in for your controller/action requests. Let's walk through the most common fixes to get your app up and running:

  • Check IIS Modules & ASP.NET Installation
    MVC relies on specific ASP.NET modules to handle route-based requests. For .NET Framework apps, make sure the ASP.NET 4.x feature is installed on your server (you can set this up via Server Manager > Add Roles and Features). For ASP.NET Core apps, you need the ASP.NET Core Hosting Bundle installed—it adds the necessary modules to route requests to your Core application.
    In IIS Manager, navigate to your site > Modules and verify routing-related modules are present (like UrlRoutingModule-4.0 for .NET Framework or AspNetCoreModuleV2 for ASP.NET Core).

  • Validate Routing Configuration
    Double-check your route setup to ensure it's mapping requests correctly:

    • For .NET Framework: Open Global.asax and confirm the default route is registered in RouteConfig.cs:
      routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
      );
      
      Also make sure your controller class names end with Controller (e.g., HomeController) and your action method is public.
    • For ASP.NET Core: Check Program.cs (or Startup.cs for older versions) to ensure MapControllerRoute is configured properly for your routes.
  • Enable the URL Rewrite Module
    IIS needs the URL Rewrite module to translate clean controller/action URLs into requests the MVC framework can process. If this module isn't installed, IIS will treat your route as a missing static file and return a 404. You can install it through the IIS Manager's Web Platform Installer.

  • Verify Application Pool Settings
    Your app pool's configuration must match your MVC project's framework:

    • For .NET Framework: Set the .NET CLR Version to v4.0 (matching your project's target framework) and confirm the pool is running.
    • For ASP.NET Core: Set the .NET CLR Version to No Managed Code since Core apps self-host their runtime.
      Also, ensure the app pool identity has read permissions to your application's root directory.
  • Check Web.config for Routing & Error Settings

    • For .NET Framework: Ensure your Web.config includes the routing module registration. You can temporarily set <customErrors mode="Off"/> to see detailed error messages instead of the generic 404—this might reveal missing DLLs or configuration missteps.
    • For ASP.NET Core: Confirm the auto-generated web.config has the correct AspNetCore handler configuration pointing to your app's DLL.
  • Confirm Deployment Files Are Complete
    Double-check that all necessary files are deployed:

    • For .NET Framework: Make sure the bin directory contains all required DLLs (like System.Web.Mvc.dll, System.Web.Routing.dll, and your project's compiled DLLs). Missing these will break routing entirely.
    • For ASP.NET Core: Verify all published files (including runtime files, your app DLL, and configuration files) are present on the server.

Start with checking IIS modules and app pool settings first—those are the most common culprits when static files work but MVC routes don't. Enabling detailed errors will also give you a clearer picture of exactly what's going wrong!

内容的提问来源于stack exchange,提问作者Imad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:14:31