When working with ASP.NET Core MVC applications, one of the most common issues developers face is the 404 – Page Not Found error. The browser typically shows:
This localhost page can’t be found
No web page was found for the web address:
https://localhost:7104/JobRolesController/index
HTTP ERROR 404
This error appears when the URL does not match a valid route, or when the controller, view, or routing configuration is incorrect.
In this article, we will understand why this error occurs and how to fix it step by step.
1. Understanding Why the Error Occurs
If your controller name is:
public class JobRolesController : Controller
{
public IActionResult Index()
{
return View();
}
}
You must access it using:
https://localhost:7104/JobRoles/Index
But many beginners make this mistake:
https://localhost:7104/JobRolesController/Index
This will always produce HTTP ERROR 404.
ASP.NET Core automatically removes the word “Controller” in the route.
2. Correct URL Format in ASP.NET Core MVC
The correct format is:
/ControllerNameWithoutController/ActionName
So for:
JobRolesController.cs
Index() action
The correct URL becomes:
https://localhost:7104/JobRoles/Index
Or simply:
https://localhost:7104/JobRoles
(because MVC loads the Index() method by default)
3. Verify Default Routing in Program.cs
Your Program.cs file must have the following route configuration:
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
If this line is missing, routing will not work, resulting in a 404 error.
Ensure you have:
builder.Services.AddControllersWithViews();
app.MapControllers();
This enables the MVC engine.
4. Ensure the View Exists in the Correct Folder
For MVC to load the view, the file must exist here:
Views
└── JobRoles
└── Index.cshtml
If:
→ The framework throws a 404 error.
Make sure the folder name matches the controller name without “Controller”.
5. Double-Check Launch URL and Port
Sometimes the issue is as simple as hitting the wrong port.
Check launchSettings.json:
"applicationUrl": "https://localhost:7104;http://localhost:5104"
If you use a different port in the browser, you will get 404.
6. Most Common Causes of 404 in ASP.NET Core
| Cause | Description |
|---|
| Wrong Controller Route | Using /ControllerNameController/Index instead of /ControllerName |
| Missing Index() Method | No action method → route can’t match |
| Missing Index.cshtml | View not found under Views → JobRoles folder |
| Folder Name Spelling | Jobroles ≠ JobRoles (case matters in Linux/macOS) |
| Wrong Port Number | Using unmatched localhost port |
| Routing Not Configured | Missing MapControllerRoute in Program.cs |
| MVC Not Enabled | AddControllersWithViews() missing |
7. Quick Checklist to Fix the Error
| Step | Check |
|---|
| 1 | URL must be /JobRoles/Index |
| 2 | JobRolesController must exist |
| 3 | Index() action must exist |
| 4 | Views → JobRoles → Index.cshtml must exist |
| 5 | Program.cs must contain default route |
| 6 | Correct localhost port must be used |
Conclusion
The HTTP ERROR 404 in ASP.NET Core usually comes from incorrectly formed URLs or missing MVC configurations.
By following the steps in this article, you can quickly identify and fix the root cause.
Remember:
1. Controller name in URL should not contain “Controller”
Correct routing must exist
Views must be in the correct folder
Ports must match launchSettings.json
Once these are correct, your application will start working without issues.