One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.net could not pull content or data from www.bing.com.

One way to overcome this issue is by using a server-side proxy on the site running the JavaScript code. There is already are well documented PHP solutions on the web, however I couldn’t find very many .NET-based solutions. This simple C# code takes the URL passed to it through the URL encoded query string, retrieves the content of the URL and outputs it as if it were content on the site.

Proxy.aspx.cs

Proxy.aspx

The Proxy.aspx page is simply blank except for the Page tag. When passing the URL to the query string, it is important that it is URL encoded. This helps to prevent query strings of the remote site URL from interfering with the Proxy page.

Example Usage
http://www.yoursite.com/proxy.aspx?u=http%3a%2f%2fwww.google.com

ASP.NET Proxy Page Source

Happy coding!

Pin It on Pinterest

Share This
%d bloggers like this: