POST route restriction error

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:

//route definition
        routes.MapRoute(
            "default route" ,
            "{controller}/{action}/{id}" ,
            new { id = UrlParameter.Optional },
            new { id = @"^\d+$" }
        );

//action definition (note I also tried with only [HttpPost] and with nothing same result
        [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, " "

+5
3

:

HTTP- POST, '/object/edit/-2', .

:

HTTP- POST, '/profile/editlink/-2', .

Edit:

, .

, .

+1

, . , URL , , URL. , , , , . , / , .

: 2.0.0.7 ( ), , ( 1.0.0.1 NuGet), . , NuGet , , .

+1

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get )]

, ( [HttpPost], HttpGet ..).

0

All Articles