Writing a stream to the response in ASP.Net
<p>Ok just want to clarify something with my solution.</p>

<p>I have a requirement to grab a file from a respository somewhere, this repository  requires a session token to be passed in the form of a cookie along with the request for the file.  </p>

<p>I am authenticating the user against this repository and storing the session token in the users cookie collection for my application when the user first logs onto my application. </p>

<p>Problem is the cookie will not get sent to the repository when a user tried to access a file because the repository is on a different URL and domain.  Therefore I am creating a new http request, appending the cookie and getting the response stream back.</p>

<p>I now need to send this response stream back to the user, headers and all (as this response stream will contain the headers for the file the user is trying to access)</p>

<p>Can I use this:</p>

<pre><code>            string session = cookie.Value;
            StreamReader reader = new StreamReader(Utility.GetLinkStream(url, session));
            Context.Response.ClearHeaders();
            Context.Response.Clear();
            Context.Response.Write(reader.ReadToEnd());
</code></pre>

<p>Essentially the call to Utility.GetLinkStream goes off and creates a http request then returns the stream of the response.  Will the call to Write write out the whole response headers and all, or is there a better way to acheive this?</p>
