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

VS2017中克隆的ASP.NET Core项目IIS Express运行时API全返回404

Troubleshooting 404 Not Found for ASP.NET Core API in IIS Express

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.json configuration
    This file lives in the Properties folder of your project, and it’s often the culprit for mismatched URLs. Verify:

    • The applicationUrl under the "IIS Express" section matches the base URL you’re using to test endpoints (e.g., http://localhost:5000 or https://localhost:44300).
    • The launchUrl points to a valid API path (like api/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 of http://.

  • 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 either services.AddControllers() (for API-only projects) or services.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 a UsersController maps to api/users).

  • Reset IIS Express configuration
    Corrupted local IIS Express settings can break routing. Try this:

    • Close Visual Studio completely.
    • Delete the hidden .vs folder 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 (or Startup.cs for 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.
  • 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:48:48