title: Read Asp.Net Core Response body in ActionFilterAttribute
body: <p>I'm using Asp.Net Core as a Rest Api Service.
  I need access to request and response in ActionFilter. Actually, I found the request in OnActionExcecuted but I can't read the response result.</p>
  
  <p>I'm trying to return value as follow:</p>
  
  <pre><code>[HttpGet]
  [ProducesResponseType(typeof(ResponseType), (int)HttpStatusCode.OK)]
  [Route("[action]")]
  public async Task&lt;IActionResult&gt; Get(CancellationToken cancellationToken)
  {
      var model = await _responseServices.Get(cancellationToken);
      return Ok(model);
  }
  </code></pre>
  
  <p>And in ActionFilter OnExcecuted method as follow:</p>
  
  <pre><code>_request = context.HttpContext.Request.ReadAsString().Result;
  _response = context.HttpContext.Response.ReadAsString().Result; //?
  </code></pre>
  
  <p>I'm trying to get the response in ReadAsString as an Extension method as follow:</p>
  
  <pre><code>public static async Task&lt;string&gt; ReadAsString(this HttpResponse response)
  {
       var initialBody = response.Body;
       var buffer = new byte[Convert.ToInt32(response.ContentLength)];
       await response.Body.ReadAsync(buffer, 0, buffer.Length);
       var body = Encoding.UTF8.GetString(buffer);
       response.Body = initialBody;
       return body;
   }
  </code></pre>
  
  <p>But, there is no result!</p>
  
  <p>How I can get the response in OnActionExcecuted? </p>
  
  <p>Thanks, everyone for taking the time to try and help explain</p>