Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

ASP.Net reverse proxy image problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Mathew - 20 Jun 2007 22:42 GMT
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.
George Ter-Saakov - 21 Jun 2007 14:40 GMT
I would recomend to intall fiddler.
http://www.fiddlertool.com/fiddler/

to see what your browser is getting back from your proxy.

George.

> 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
[quoted text clipped - 39 lines]
> pages so that makes me think it's something else I'm overlooking. Any
> help would be greatly appreciated.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.