title: Understanding SendAsync method ASP.net web API Message Handlers
body: <p>I am trying to implement a custom Message Handler, below is the code.</p>
  
  <pre><code>public class MyHandler : DelegatingHandler
  {
      protected override async Task&lt;HttpResponseMessage&gt; SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
      {
          /* Code that executes while receiving the request - start */
          bool isBadrequest = false;
  
          if (isBadrequest)
          {
              return request.CreateResponse(System.Net.HttpStatusCode.NotFound,"test");
          }
         /* Code that executes while receiving the request - end */
  
         /* Code that executes while sending the response - start */            
          var response = await base.SendAsync(request , cancellationToken);
          response.Headers.Add("new header", "new header value");
          return response;
         /* Code that executes while sending the response - end */
      } 
  }
  </code></pre>
  
  <p>I am aware of Tasks and async/await in C#.
  But I am unable to understand how the same method gets executed both while receiving the request and sending the response.</p>