ASP.NET Core  

How to Fix “This localhost page can’t be found – HTTP ERROR 404” in ASP.NET Core

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:

  • folder name is incorrect, or

  • view file name is wrong

→ 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

CauseDescription
Wrong Controller RouteUsing /ControllerNameController/Index instead of /ControllerName
Missing Index() MethodNo action method → route can’t match
Missing Index.cshtmlView not found under Views → JobRoles folder
Folder Name SpellingJobroles ≠ JobRoles (case matters in Linux/macOS)
Wrong Port NumberUsing unmatched localhost port
Routing Not ConfiguredMissing MapControllerRoute in Program.cs
MVC Not EnabledAddControllersWithViews() missing

7. Quick Checklist to Fix the Error

StepCheck
1URL must be /JobRoles/Index
2JobRolesController must exist
3Index() action must exist
4Views → JobRoles → Index.cshtml must exist
5Program.cs must contain default route
6Correct 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. 1. Controller name in URL should not contain “Controller”

  2. Correct routing must exist

  3. Views must be in the correct folder

  4. Ports must match launchSettings.json

Once these are correct, your application will start working without issues.