You receive an HTTP 404 ERROR with an ASP.NET Core API or Website Print

  • 30

Troubleshooting HTTP 404 Errors in ASP.NET Core

Updated: This article covers both the modern minimal hosting (Program.cs) for .NET 6+ and legacy Startup.cs pattern.

Common Causes of 404 Errors

  1. Application not running or failed to start
  2. Missing or incorrect route configuration
  3. Controller/endpoint not registered
  4. Incorrect Application Startup File in Plesk
  5. Files not uploaded correctly

Step 1: Verify Application is Running

Check if your app started successfully:

  1. In Plesk, go to Fileshttpdocs/logs
  2. Check the latest stdout log for errors
  3. If no logs exist, enable stdout logging in web.config

Step 2: Verify Published Files

Ensure these files exist in httpdocs:

  • YourApp.dll (main application)
  • YourApp.deps.json
  • YourApp.runtimeconfig.json
  • web.config

Step 3: Check Route Configuration

Modern Pattern: Program.cs (.NET 6, 7, 8, 9, 10)

var builder = WebApplication.CreateBuilder(args);

// Add services
builder.Services.AddControllers();  // For API controllers
// OR
builder.Services.AddControllersWithViews();  // For MVC
// OR
builder.Services.AddRazorPages();  // For Razor Pages

var app = builder.Build();

// Configure middleware
app.UseRouting();
app.UseAuthorization();

// Map endpoints
app.MapControllers();  // For API with [Route] attributes
// OR
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");  // For MVC
// OR
app.MapRazorPages();  // For Razor Pages

app.Run();

Legacy Pattern: Startup.cs (.NET Core 3.1, 5.0)

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

Step 4: Verify Controller Routes

For Web API controllers, ensure routes are defined:

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    [HttpGet]
    public IActionResult GetAll() => Ok(new[] { "Product1", "Product2" });

    [HttpGet("{id}")]
    public IActionResult GetById(int id) => Ok($"Product {id}");
}

This creates endpoints at /api/products and /api/products/{id}

Step 5: Check Plesk Settings

  1. Go to Websites & DomainsHosting Settings
  2. Verify Application Startup File matches your DLL name exactly
  3. Verify .NET Core Version matches your target framework
  4. Click OK and test again

Step 6: Restart Application

  1. Go to Websites & Domains
  2. Find your domain and click Restart App in .NET Core section
  3. Or recycle the Application Pool via Dedicated IIS Application Pool

Common Mistakes

  • Missing [ApiController] attribute on API controllers
  • Missing [Route] attribute when using attribute routing
  • Calling app.Run() before app.MapControllers()
  • Not calling AddControllers() in service configuration
  • Case sensitivity in route URLs

Testing Your Routes

Use browser developer tools or Postman to test:

  • Check the exact URL being requested
  • Verify HTTP method (GET, POST, etc.) matches your endpoint
  • Check response headers for clues

Was this answer helpful?

« Back