title: IHttpHandler send cookie back to calling website
body: <p>I have an ordering website that needs to make a set up request on a supplier site.
  For this i am using a WebHanlder (ashx file) to read the setup request in cXML using the HttpContext object which is working fine.</p>
  
  <p>One of the requirements is that we send back a Cookie called "Buyer Cookie" along with a cXML 200 OK response.</p>
  
  <p>The problem I am having is when I create a cookie in the context.Response it is not recieved in the ordering site when I do the <code>response.Output.Write().</code></p>
  
  <p>I have tried using <code>response.Flush()</code> after the write and this is still not working</p>
  
  <p>How can I send a cookie back to the calling site?</p>
  
  <p>Here is my code:</p>
  
  <p><strong>Ordering site</strong></p>
  
  <pre><code>Stream stream = null;
  byte[] bytes = Encoding.ASCII.GetBytes(File.ReadAllText(@"D:\Prototypes\HTTPPost\cXMLFiles\PunchOutSetupRequest.xml"));
  HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost:45454/PunchOutRequest.ashx");
  
  webRequest.ContentType = "application/x-www-form-urlencoded";
  webRequest.Method = "POST";
  webRequest.ContentLength = bytes.Length;
  
  try
  {
      stream = webRequest.GetRequestStream();
      stream.Write(bytes, 0, bytes.Length);
  }
  catch (Exception)
  {
      throw;
  }
  finally
  {
      if (stream != null)
          stream.Close();
  }
  
  HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
  Stream responseStream = response.GetResponseStream();
  StreamReader responseReader = new StreamReader(responseStream);
  
  string r = responseReader.ReadToEnd();
  var buy = webRequest.CookieContainer;
  var buyer = response.Cookies["BuyerCookie"]; // This is always null
  </code></pre>
  
  <p><strong>Supplier Site</strong></p>
  
  <pre><code>var request = context.Request;
  StreamReader reader = new StreamReader(request.InputStream);
  
  string text = reader.ReadToEnd();
  
  POSetup setup = new POSetup();
  
  if (setup.IsSetupRequestValid(text))
  {
      HttpCookie cookie = new HttpCookie("BuyerCookie", "100");
  
      context.Response.Cookies.Add(cookie);
      context.Response.Output.Write(setup.GetOKResponse());
  }
  </code></pre>