you can use the Response.StatusCode property to return 404:
Page.Response.StatusCode = 404
Regarding the question of whether this is the “right thing”, I would say that it depends on how the page is available. If you are going to access it programmatically, then yes, I would go with 404. If, however, it would be a system facing the user, then I would go with a kind of custom page. Programs such as codes and people, as more understandable things :-)
Doctor jones
source share