473,626 Members | 3,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net reverse proxy image problem

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_BeginRe quest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplicatio n)sender;
// Get image in another request
HttpWebRequest webreq = (HttpWebRequest )WebRequest.Cre ate("http://
otherserver.com/image.gif");

// Copy header variables
foreach (String each in app.Request.Hea ders)
{
if (!WebHeaderColl ection.IsRestri cted(each))
webreq.Headers. Add(each,
app.Request.Hea ders.Get(each)) ;
}

// Get Response (the image) and write it's stream back to the
original client
HttpWebResponse response = (HttpWebRespons e)webreq.GetRes ponse();
Stream responseStream = response.GetRes ponseStream();
Stream output = app.Response.Ou tputStream;
copyStream(resp onseStream, 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.

Jun 20 '07 #1
1 2671
I would recomend to intall fiddler.
http://www.fiddlertool.com/fiddler/

to see what your browser is getting back from your proxy.
George.
"Dave Mathew" <ma******@gmail .comwrote in message
news:11******** **************@ w5g2000hsg.goog legroups.com...
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_BeginRe quest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplicatio n)sender;
// Get image in another request
HttpWebRequest webreq = (HttpWebRequest )WebRequest.Cre ate("http://
otherserver.com/image.gif");

// Copy header variables
foreach (String each in app.Request.Hea ders)
{
if (!WebHeaderColl ection.IsRestri cted(each))
webreq.Headers. Add(each,
app.Request.Hea ders.Get(each)) ;
}

// Get Response (the image) and write it's stream back to the
original client
HttpWebResponse response = (HttpWebRespons e)webreq.GetRes ponse();
Stream responseStream = response.GetRes ponseStream();
Stream output = app.Response.Ou tputStream;
copyStream(resp onseStream, 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.

Jun 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
4293
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
1
6377
by: Mark Ferguson | last post by:
I've been trying to get a simple pycurl script working with an authenticating proxy, here is the code (with changes to protect the guilty!): from pycurl import * import StringIO b = StringIO.StringIO() c = Curl()
7
6760
by: JavaScriptRocks | last post by:
I've been trying to imitate / reverse engineer the add attachment feature in gmail composer. I managed to do it to say about 80% but its giving me trouble in IE on WinXP-Sp2. I am using PHP to do the upload. It works well on Firefox/DeerPark, but in IE, the file selected just vanishes. You can verify it by commenting the lines marked "//IE Trouble". Commenting those lines will remove IE specific code, except the el.click() whick sends the...
3
6624
by: A.M | last post by:
Hi, We are developing ADP.NET applications and one of our requirements is implementing a Reverse Proxy on IIS. I have couple of questions about Reverse Proxy:
2
4226
by: =?Utf-8?B?a2NtYXJzaGFsbC5tc3A=?= | last post by:
We're working on an app that will be integrated with another web app through a reverse proxy. Our aspx pages will appear in an IFrame from their site and will appear to the client browser as originating from the other app's domain. Through use of relative URLs we've believe we have links working from page to page. The problem we've discovered is with javascript, etc. emitted by WebResource.axd links. All of these links seem to be...
0
1461
by: etnaelk | last post by:
Hi all, I have a real bugger of a problem that I just haven't been able to figure out. I am working on writing my own proxy server in C# using TcpListener, TcpClient, HttpWebRequest/Response and NetworkStream. I have everything working pretty well except images won't load to their location. ------------------------------------------------------------------------------------------------------------------...
3
1733
by: Jane Parker | last post by:
I read with interest the recent posting about Reverse Proxies and wondered if it is possible to mix static and dynamic content. If you have a lot of static content on your site it would make sense to keep it outside the network, and only use the reverse proxy when making dynamic data calls, but how could that actually work in practise? Is it possible to mix it up like this?
5
2862
by: kokababu | last post by:
Hi, I have setup a reverse proxy server which will route the request to Server B. Proxy server is working well with Server B. I would like to catch HTTP status error like 404/500 from server B. If my proxy gets error404/500 from Server B then it will redirect the page to other site, using PHP. For this reason, I set ErrorDocument 404/500 on httpd.conf file in reverse proxy server to catch error from Server B. But ErrorDocument is not ...
0
1097
by: =?Utf-8?B?d2FsdGVy?= | last post by:
Hi there... I am stuck here ,and wish you could help. We have a webservice proxy, since we are moving to WCf , we will want to re-generate a new proxy. The problem is we do not own the service and ,worse, no WDSL available for us. I know JAVA world can reverse engineer proxy back to WSDL. I wish you could help me to find the similar thing in .NET. Welcome any inspiring thought.
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.