title: HttpWebResponse output stream doesn't close
body: <p>I'm writing custom <code>ActionFilterAttribute</code> and trying to write some data directly into output stream in ASP.NET MVC 3. The data that i'm writing is all that i need to be in response, but after writing there is a extra data after my data - rendered view. I'm trying to close <code>OutputStream</code>, but it still stay accesible for writing. How can I close this stream for writing or ignore following HTML rendering?</p>
  
  <pre><code>public override void OnActionExecuted(ActionExecutedContext filterContext)
  {
      var request = filterContext.RequestContext.HttpContext.Request;
      var acceptTypes = request.AcceptTypes ?? new string[] {};
      var response = filterContext.HttpContext.Response;
  
      if (acceptTypes.Contains("application/json"))
      {
          response.ContentType = "application/json";
          Serializer.Serialize(data, response.ContentType, response.OutputStream);
      }
      else if (acceptTypes.Contains("text/xml"))
      {
          response.ContentType = "text/xml";
          Serializer.Serialize(data, response.ContentType, response.OutputStream);
      }
      response.OutputStream.Close();
  }  
  </code></pre>
  
  <p><strong>UPD</strong><br>
  For example my data is <code>{"Total": 42, "Now": 9000}</code><br>
  And my view is like this</p>
  
  <pre><code>&lt;div&gt;
      &lt;span&gt;The data that shouldn't be here&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In response i get </p>
  
  <pre><code>{"Total": 42, "Now": 9000}
  &lt;div&gt;
      &lt;span&gt;The data that shouldn't be here&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and it's not valid JSON, as you can see. My aim is to send only JSON or XML</p>