Asp.Net Core 2.0 Web API部署至IIS 8.5后访问控制器均报404错误
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 includedservices.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!
- A conventional route defined, like:
- In
Inspect Published Files and
web.config- Make sure your published folder includes all required files:
web.config, compiled DLLs, and any dependencies. - Open
web.configand verify theaspNetCoresection is correct. For ASP.NET Core 2.0, it should resemble:
Temporarily set<aspNetCore processPath="dotnet" arguments=".\YourApiName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />stdoutLogEnabled="true"—this generates detailed runtime logs in thelogsfolder, which can uncover hidden issues like missing dependencies or startup crashes that cause 404s.
- Make sure your published folder includes all required files:
Test the Published Build Locally
Run your published API locally withdotnet YourApiName.dllto 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

