Writing a stream in response in ASP.Net
Ok just want to clarify something with my solution.
I have a requirement to grab a file from a repository somewhere, this repository requires the session token to be passed as a cookie along with the file request.
I validate the user to use this repository and store the session token in the user cookie collection for my application when the user first logs into my application.
The problem is that the cookie will not be pushed to the repository when the user tries to access the file as the repository is in a different url and domain. So I create a new http request, add a cookie and get a stream of responses back.
Now I need to send this response stream back to the user, headers and everyone (since this response stream will contain the headers for the file the user is trying to access)
Can I use this:
string session = cookie.Value;
StreamReader reader = new StreamReader(Utility.GetLinkStream(url, session));
Context.Response.ClearHeaders();
Context.Response.Clear();
Context.Response.Write(reader.ReadToEnd());
Basically, the call to Utility.GetLinkStream disconnects and creates an HTTP request and then returns a response stream. Will the Write call write all the response headers and everything, or is there a better way to achieve this?
source to share