Kill a http post request

2019-06-11 05:26发布

问题:

I am trying to handle the duplicated form posting by using the anti forgery token as answered here the problem arises when a duplicate identical form post request arrives it is successfully identified but i am unable to handle it properly. I am doing

   if (ctx.Session["userform"] != null)
   {
       if (_antiForgToken.Equals(ctx.Session["userform"].ToString()))
       {
           //kill the request
           response.Clear();
           response.ClearContent();
           response.Close(); 
       }
   }
   else
       ctx.Session["userform"] = _antiForgToken;          
}

the question is how can i just drop the duplicated HTTP request as if it never happened...

回答1:

You still need to respond to the request made by the client right and just killing the response will not help. Probably send a reponse with a status code 400.

400 Bad Request

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.