Frank La Vigne

Fear and Loathing in .NET

Subscription Options

Blog
Add to Google

Subscribe in Bloglines
Subscribe in NewsGator Online
Add Frank La Vigne to Newsburst from CNET News.com

Subscribe in Rojo
Podcast
Subscribe in podnova
Add Frank La Vigne to ODEO

My Links

News






Post Categories

Archives

Image Galleries

Blog Stats

Blog Roll

Favorite Sites

Gadget Blogs

Tablet PC Links

Silverlight 2 Cross Domain Web Proxy Utility

Ever since Ian Griffiths' post on a bug in Cross Domain web access and my own experiments, I decided to create a web proxy class that creates web request to a URI from a remote site and passes the data back to the client.

The code preserves Mime Types, so it works with images/media files as well as text based files.

In other words, you can access any file type on the web, regardless of that site's Cross Domain access policy.

Just place this ASPX page on a site whose Cross Domain policy you can control.

Here's the main piece of the code:

// Make new WebClient
WebClient webClientRequest = new WebClient();

// Download data from URI
byte[] requestByteArray = webClientRequest.DownloadData(sourceUriString);

// Match the Mime Types
string contentType = webClientRequest.ResponseHeaders["Content-type"].ToString();
Response.ContentType = contentType;

// Copy the Streams
int requestByteArrayLength = requestByteArray.GetLength(0);
Response.OutputStream.Write(requestByteArray, 0, requestByteArrayLength);
Response.OutputStream.Close();

// Exit the Page
Response.End();

 

[Download Source Code 3k]

posted on Tuesday, March 18, 2008 1:51 PM