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

Asp.Net Core 2.0 Web API部署至IIS 8.5后访问控制器均报404错误

Troubleshooting 404 Errors for ASP.NET Core 2.0 Web API Hosted on IIS

Hey there, sorry to hear you're hitting consistent 404 errors after deploying your ASP.NET Core 2.0 Web API to IIS. Let's work through some targeted checks and fixes—since you mentioned standard Google searches didn't help, we'll cover both common and slightly less obvious angles.

Key Checks to Resolve the 404s

  • Confirm the ASP.NET Core Module is Installed
    IIS requires the ASP.NET Core Module to forward requests to your API's Kestrel server. Head to IIS Manager → Server Features, and verify "ASP.NET Core Module" is listed under HTTP Features. If it's missing, install the matching ASP.NET Core Hosting Bundle for 2.0 (you can grab this via Windows Server's Add Roles and Features wizard or Microsoft's official downloads).

  • Fix Application Pool Settings

    • Set your application pool's .NET CLR Version to No Managed Code—ASP.NET Core runs independently of IIS's managed runtime, so this setting is non-negotiable.
    • Ensure the application pool identity has read/write permissions to your API's published folder. Silent permission issues often masquerade as 404 errors.
  • Validate Routing Configuration in Startup.cs
    Since all controllers are returning 404s, routing misconfiguration is a likely culprit:

    • In ConfigureServices, confirm you've included services.AddMvc(); (this enables Web API routing by default in ASP.NET Core 2.0).
    • In Configure, check that you have either:
      • A conventional route defined, like:
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "api/{controller}/{action}/{id?}");
        });
        
      • Or properly applied attribute routing to your controllers (e.g., [Route("api/[controller]")] on controller classes and [HttpGet]/[HttpPost] on action methods). Double-check for typos in route templates!
  • Inspect Published Files and web.config

    • Make sure your published folder includes all required files: web.config, compiled DLLs, and any dependencies.
    • Open web.config and verify the aspNetCore section is correct. For ASP.NET Core 2.0, it should resemble:
      <aspNetCore processPath="dotnet" arguments=".\YourApiName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      
      Temporarily set stdoutLogEnabled="true"—this generates detailed runtime logs in the logs folder, which can uncover hidden issues like missing dependencies or startup crashes that cause 404s.
  • Test the Published Build Locally
    Run your published API locally with dotnet YourApiName.dll to rule out application-level issues. If it fails here, the problem is in your code or configuration, not IIS.

If none of these steps fix the problem, sharing your Program.cs and Startup.cs code will help us dig into more specific configuration issues. Let me know what you find!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:53:46