title: adding header to http response in an action inside a controller in asp.net/mvc
body: <p>I am streaming data from server to client for download using <code>filestream.write</code>. In that case what is happening is that I am able to download the file but it does not appear as download in my browser. Neither the pop-up for "Save As" appears not "Download Bar" appears in Downloads section. From looking around, I guess I need to include "something" in the response header to tell the browser that there is an attachment with this response. Also I want to set the cookie. To accomplish this, this is what I am doing:</p>
  
  <pre><code>        [HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" &amp; name)]
      public ActionResult Download(string name)
      {
            // some more code to get data in inputstream.
  
            using (FileStream fs = System.IO.File.OpenWrite(TargetFile))
              {
                  byte[] buffer = new byte[SegmentSize];
                  int bytesRead;
                  while ((bytesRead = inputStream.Read(buffer, 0, SegmentSize)) &gt; 0)
                  {
                      fs.WriteAsync(buffer, 0, bytesRead);
                  }
              }
          }
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>I am getting error that: "System.web.httpcontext.current is a property and is used as a type."</p>
  
  <p>Am I doing the header updating at the right place? Is there any other way to do this?</p>