When you manipulate data in action, you often get an identifier as a parameter, but you need to do some error handling for that identifier. One of the processing errors you must perform for each action is to make sure the identifier is above 0 (and not a negative number). Therefore, instead of handling this in action, I wanted to add a route restriction, so we just do not route the action if its identifier is negative.
Here is my code:
routes.MapRoute(
"default route" ,
"{controller}/{action}/{id}" ,
new { id = UrlParameter.Optional },
new { id = @"^\d+$" }
);
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get )]
public ActionResult Edit( int id )
Everything works fine when you execute GET , but when I POST , I get the following error when I just need to go to page 404
HTTP verb POST used to access path '/object/edit/-2' is not allowed.
[HttpException (0x80004005): The HTTP verb POST used to access path '/object/edit/-2' is not allowed.]
System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) +740
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +632
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +194
Any ideas? Perhaps the best solution?
EDIT: - , , 500, 405, " "