title: Download file from controller
body: <p>In an Aspnet5 RC1 update1 web application, I am trying to do the same as Response.BinaryWrite, file download in old AspNet application.</p>
  <p>The user needs to get a popup save dialog in client side.</p>
  <p>When the following code is used, a popup prompt appears in client side to save the file:</p>
  <pre><code>public void Configure(IApplicationBuilder app)
  {
      //app.UseIISPlatformHandler();
      //app.UseStaticFiles();
      //app.UseMvc();
      app.Run(async (objContext) =&gt;
      {
          var cd = new System.Net.Mime.ContentDisposition { 
                       FileName = &quot;test.rar&quot;, Inline = false };
          objContext.Response.Headers.Add(&quot;Content-Disposition&quot;, cd.ToString());
          byte[] arr = System.IO.File.ReadAllBytes(&quot;G:\\test.rar&quot;);
          await objContext.Response.Body.WriteAsync(arr, 0, arr.Length);
      });
  }
  </code></pre>
  <p>But when the same code is used inside a Controller's action, app.Run is commented out, the save popup does not appear, the content is just rendered as text.</p>
  <pre><code>[Route(&quot;[controller]&quot;)]
  public class SampleController : Controller
  {
      [HttpPost(&quot;DownloadFile&quot;)]
      public void DownloadFile(string strData)
      {
          var cd = new System.Net.Mime.ContentDisposition { 
                       FileName = &quot;test.rar&quot;, Inline = false };                
          Response.Headers.Add(&quot;Content-Disposition&quot;, cd.ToString());
          byte[] arr = System.IO.File.ReadAllBytes(&quot;G:\\test.rar&quot;);                
          Response.Body.WriteAsync(arr, 0, arr.Length);  
  </code></pre>
  <p>Control flow needs to come to controller, perform some logic, then send byte[] response content to client side, then the user needs to save the file. There is no cshtml, just plain html with jquery ajax call.</p>