Momen Alnaser
Momen Alnaser

Reputation: 85

page not found 404 - Index Action

My solution was working very well, suddenly I got (page not found 404 error) for two controllers only for Index Actions !! and the other Index actions in other controllers are working fine.

UsersController

public async Task<IActionResult> Index()
{
    return View(await _context.Users.ToListAsync());
}
[HttpPost]

public async Task<IActionResult> Index([FromForm] string search)
{
    if (!User.Identity.IsAuthenticated) RedirectToAction("Index", "Home");
    if (!string.IsNullOrWhiteSpace(search))
    {

        search = search.Trim().ToLower();
        ViewBag.Search = search;
        return View(_context.Users.Where(x => x.NormalizedUsername.Contains(search)).ToList());
    }
    else
        return View(await _context.Users.ToListAsync());
}

any help/clue where I should check? thanks

Upvotes: 2

Views: 578

Answers (1)

Fei Han
Fei Han

Reputation: 27825

I got (page not found 404 error) for two controllers only for Index Actions

Please check the conventional routing you configured in StartUp.Configure method, then compare it with your actual request URL and check if some required segment or data is missing in request URL.

https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-5.0#conventional-routing

And please check if you are using any attribute route or URL rewriting rule, which might cause similar issue.

Besides, you can try to modify log level to get detailed routing diagnostic logs.

https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-5.0#debug-diagnostics

Upvotes: 1

Related Questions