I have a publicly available controller (The action cannot be hidden under any security attribute) . The controller has an action which is available publicly as well.
Following is a sample structure of the controller :
public SomeController : Controller {
[HttpGet]
public ActionResult show(int id){
}
}
The action has a id field which is required. However throws an error which unnecessary adds to the logs when someone enters a malformed URL without the required id (or when search engine bots hit the a URL with the required id).
What should be the ideal solution to deal with this solution.
Possible solutions that come to my mind are :
- Set the id as Nullable (int? id) and explicitly handle the case of not having a value by redirecting the caller to some other page showing appropriate errors
- explicitly send a 404 error
Is there a generic way using Attributes to do this?
P.S : (to be specific) by explicit I mean writing if else conditions to handle such cases per controller.
I would appreciate any hints in the right direction.