title: c# async file extension check with action filter ActionFilterAttribute
body: <p>The idea behind is that I have an ActionFilterAttribute who is checking the file extension. If the file extension exist it can pass otherwise throw an error. I have multiple fileuploads on diffrent places.</p>
  
  <p>I have a singlepage application running where user can upload files. It runs on javascript knockout.js and c#.</p>
  
  <p>The problem is that I get always Count = 0 in the MultipartMemoryStreamProvider</p>
  
  <p>Here is the code who is calling the ActionFilterAttribute on the first line</p>
  
  <pre><code>[DocumentUploadValidationAttribute]
      [HttpPost, Route("documents/upload/{customerId}/{documentType}")]
      public async Task&lt;IHttpActionResult&gt; UploadCustomerDocument(int customerId, string documentType)
      {
          try
          {
              await data.Document.UploadCustomerDocument(Request, customerId, documentType);
              return Ok();
          }
          catch (Exception ex)
          {
              return BadRequest(ex.Message);
          }
      }
  </code></pre>
  
  <p>The ActionFilterAttribute looks like this. In the foreach loop provider.Content is 0 but why?</p>
  
  <pre><code>namespace VZ.VMS.UI.Validation {
  public class DocumentUploadValidationAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
          var provider = new MultipartMemoryStreamProvider();
          var task = actionContext.Request.Content.ReadAsMultipartAsync(provider);
  
          foreach (var file in provider.Contents)
          {
              var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
              var extension = Path.GetExtension(filename).Replace(".", "");
  
              if (extension != "pdf" &amp;&amp; extension != "docx" &amp;&amp; extension != "xlsx" &amp;&amp; extension != "img" &amp;&amp; extension != "png")
              {
                  actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, new { errorMessage = "error_code" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
              }
          }
  
          base.OnActionExecuting(actionContext);
      }
  }
  }
  </code></pre>