VS2017中克隆的ASP.NET Core项目IIS Express运行时API全返回404
Hey there, let's work through this frustrating 404 issue you're hitting with your cloned ASP.NET Core project in Visual Studio 2017. I’ve dealt with similar roadblocks before, so here are targeted steps to diagnose and fix the problem:
Double-check your
launchSettings.jsonconfiguration
This file lives in thePropertiesfolder of your project, and it’s often the culprit for mismatched URLs. Verify:- The
applicationUrlunder the "IIS Express" section matches the base URL you’re using to test endpoints (e.g.,http://localhost:5000orhttps://localhost:44300). - The
launchUrlpoints to a valid API path (likeapi/values) to ensure you’re starting at a working endpoint. - Example correct snippet:
"IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }
Also, make sure you’re not mixing HTTP and HTTPS—if the config uses HTTPS, test endpoints with
https://instead ofhttp://.- The
Validate your minimal Mvc routing setup
Even though you stripped down the Startup class, confirm these critical pieces are in place:- In
ConfigureServices, you have eitherservices.AddControllers()(for API-only projects) orservices.AddMvc()(older ASP.NET Core versions). - In
Configure, you’ve added the routing middleware:app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); // Maps attribute-based routes from controllers });
Check your controller classes too—ensure they have
[ApiController]and valid[Route]attributes (e.g.,[Route("api/[controller]")]for aUsersControllermaps toapi/users).- In
Reset IIS Express configuration
Corrupted local IIS Express settings can break routing. Try this:- Close Visual Studio completely.
- Delete the hidden
.vsfolder in your project’s root directory (this stores local IIS Express configs). - Reopen the project and rebuild it—Visual Studio will regenerate fresh IIS Express settings.
- You can also try changing the port number in the project’s debug settings (right project → Properties → Debug) to rule out port conflicts.
Confirm the correct startup project
It’s easy to overlook: make sure the dropdown next to the Visual Studio "Start" button is set to your API project (not a different project or the default IIS Express site). If you’re working with a solution, right-click your API project → Set as Startup Project.Inspect routing logs for clues
Enable debug-level logging to see exactly what routes are registered and why requests aren’t matching:- In
Program.cs(orStartup.csfor pre-.NET 6 projects), add:// .NET 6+ example builder.Logging.AddDebug().SetMinimumLevel(LogLevel.Debug); - Open the Output window in Visual Studio, select "ASP.NET Core Web Server" from the dropdown, and look for logs about route matching. You’ll see which routes are available and if your request is failing to match any of them.
- In
Verify framework and dependency setup
- Ensure Visual Studio 2017 supports your project’s target framework (e.g., .NET Core 2.1 or 3.1 requires the corresponding SDK installed). Check this in project properties → Application → Target Framework.
- Right-click the solution → Restore NuGet Packages to make sure all dependencies (like ASP.NET Core MVC) are properly installed and up to date.
Hope one of these steps gets your API endpoints responding correctly. Let me know if you need to dig into any of these checks further!
内容的提问来源于stack exchange,提问作者Radu Ungureanu

