Hi
I have a aspx page that seems to be loading twice when I enter the Url to the page.
In this page's loading event, I'm making an connection to a server to retrieve a document and then I output the downloaded bytes to the output stream of the page.
This is causing the page to load twice for some strange reason. If I hard code a byte array without making this connection, the page loads once and all is well.
Here are the methods used to retrieve the external document. Maybe you can see something I can't.
public static byte[] GetDocument(string url)
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream stream = myHttpWebResponse.GetResponseStream();
byte[] _Data = StreamToBytes(stream);
return _Data;
}
private static byte[] StreamToBytes(System.IO.Stream theStream)
{
if (theStream == null)
throw new ArgumentException("URL null.");
int bytesRead = 0;
byte[] buffer = new byte[8096];
MemoryStream bufferStream = new MemoryStream();
try
{
do
{
bytesRead = theStream.Read(buffer, 0, 8096);
bufferStream.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
}
finally
{
bufferStream.Flush();
theStream.Close();
theStream.Dispose();
}
return bufferStream.ToArray();
}