ASP.Net reverse proxy image problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm attempting to write a reverse proxy in ASP.Net which will catch
requests to my server in ASP.Net, perform some actions, and then get
the desired resource off another server to return to the original
client (using HttpWebRequest and rewriting it's response to my ASP.Net
client). I'm able to get the reverse proxy to work for html pages but
it's not working for images. Right now the code I'm playing with is
similar to this:

void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
// Get image in another request
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create("http://
otherserver.com/image.gif");

// Copy header variables
foreach (String each in app.Request.Headers)
{
if (!WebHeaderCollection.IsRestricted(each))
webreq.Headers.Add(each,
app.Request.Headers.Get(each));
}

// Get Response (the image) and write it's stream back to the
original client
HttpWebResponse response = (HttpWebResponse)webreq.GetResponse();
Stream responseStream = response.GetResponseStream();
Stream output = app.Response.OutputStream;
copyStream(responseStream, output);
}

When I debug the code seems to be getting the stream for the image ok
(if I do this in a windows forms app I can get an image from the
stream and show it in a picture box just fine), but the browser
apparently isn't receiving the response it expects because it either
gives an error or if the requested image is part of another page it
shows the familiar image not found icon. I've looked at a few other
reverse proxy's in ASP.Net and they don't seem to be doing anything
special for different types of files so I'm not sure what I'm doing
wrong here... any suggestion? I thought maybe having this code in the
BeginRequest event may be part of the problem, but it works for HTML
pages so that makes me think it's something else I'm overlooking. Any
help would be greatly appreciated.

.



Relevant Pages

  • Re: ASP.Net reverse proxy image problem
    ... requests to my server in ASP.Net, perform some actions, and then get ... client (using HttpWebRequest and rewriting it's response to my ASP.Net ... // Get Response and write it's stream back to the ...
    (microsoft.public.dotnet.framework.aspnet)
  • [UNIX] Apache/Tomcat Denial of Service and Information Leakage Vulnerability
    ... Beyond Security would like to welcome Tiscali World Online ... Apache has been the most popular web server on the Internet for the ... A client may connect to the target machine and deliver several requests ... and again sends a second response back to mod_jk. ...
    (Securiteam)
  • Re: Do I want an ACK in my high-level protocol when using TCP?
    ... requests, perhaps dozens, with the same "request ID", and they are ... to minimize network usage. ... receives a response, ... it's much better to call it a session ID. ...
    (comp.unix.programmer)
  • RE: HTTPS WebRequest and WebResponse
    ... > // Creates an HttpWebRequest for the specified URL. ... > // Displays all the headers present in the response received from the URI. ... > // Obtain a 'Stream' object associated with the response object. ... > StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Read everything from socket
    ... There is no standard way to indicate a stream is finished ... line from the RETR command ... Or from the LIST command ... the actual byte length is given of the response steam. ...
    (perl.beginners)