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
- Application not running or failed to start
- Missing or incorrect route configuration
- Controller/endpoint not registered
- Incorrect Application Startup File in Plesk
- Files not uploaded correctly
Step 1: Verify Application is Running
Check if your app started successfully:
- In Plesk, go to Files → httpdocs/logs
- Check the latest stdout log for errors
- 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
- Go to Websites & Domains → Hosting Settings
- Verify Application Startup File matches your DLL name exactly
- Verify .NET Core Version matches your target framework
- Click OK and test again
Step 6: Restart Application
- Go to Websites & Domains
- Find your domain and click Restart App in .NET Core section
- 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