Search code examples
iis-7httpmodule

Return request HttpModules as quickly as possible


In a web site I capture the http POST request with a HttpModule as in this answer.

After reading the body of the POST in the context's BeginRequest event I would like to return as quickly as possible an "OK" response to the client.
What would be the best way to prevent further processing in IIS (7.5 integrated mode)?


Solution

  • I believe this one is the fastest:

    Response.Clear();
    Response.ClearHeaders();
    
    Response.StatusCode = 200;
    Response.StatusDescription = "OK";
    
    Response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();