ASP.NET Core 8: Return 404 for every POST action that is outside of /api

  Kiến thức lập trình

Current situation: I run some controllers under /api/* and an SPA under /en/*

Some crappy crawler or bots make some invalid POST calls like /en/index.php that does not exists.

This results in an exception like this:

An unhandled exception has occurred while executing the request.                                                                                                                           
      System.InvalidOperationException: The SPA default page middleware could not return the default page '/en/index.html' because it was not found, and no other middleware handled the request.

Is it possible to return an clean 404 on every post action that is not handled by /api?

LEAVE A COMMENT