ASP.NET Proxy Page – Used for Cross Domain Requests from AJAX and JavaScript

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 could not pull content or data from

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.



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

ASP.NET Proxy Page Source

Happy coding!


  1. Brilliantly simple solution, thanks! This will work wonders on our SharePoint intranet.

    • That is exactly what I use this for. I place the page in the LAYOUTS folder on the server to make it available to all the SP sites. I primarily use it for consuming RSS feeds across domains.

  2. Well done. Good to see what’s possible.

  3. But it doesn’t support POST.

    • In what scenario would you want to POST to this proxy page?

      • In case you are using a REST based service and don’t want to use the ugly GET? :-)

        • Your REST based service is very RESTful if it isn’t using GET for READING DATA.

          I can see that using a POST might be desirable to post to another server and make sure the Proxy follows any redirects for you.

  4. After seeing this,, I can think of several situations where you might want to “POST” data to a remote web-service, and stick the results in a local page e.g.
    * Exchange rate conversion,
    * Stock price lookup,
    * delivery rate lookup.
    Personally I’d use Apache to Reverse Proxy the requests to the remote site, by adding the entries below to the httpd.conf, but there are plenty of equivalents for IIS, out there e.g.

    #— cut ‘n’ paste into you Apache httpd.conf —
    ProxyRequests Off

    Order deny,allow
    Allow from all

    ProxyPass /proxy http://www.some.webservice
    ProxyPassReverse /proxy http://www.some.webservice
    #—- Cut ends —

  5. It is great to see what is possible!

  6. Lovely and simple.

    I would very much to use this to set the src-attribute for an img, but it does not seem to work. Any ideas?

    • Can you explain the scenario a bit more? I’m not sure I see a correlation between this proxy solution to populating the src for an image.

      • John,

        I also have the requiremnt to proxy the SRC attribute of an image. The scenario is that a page reads the contents of an RSS feed (not my own) which resides on a different domain. The description tag of the RSS feed contains HTML mark-up included within it including an image.

        The image doesn’t currently display which i believe is due to the cross domain requests restriction. I would like to deliver the contents of the image via a proxy page in a similar to which you have described. I have based my attempt on your example provided but have been unable to get it to work.

  7. You also need to copy the user-agent
    request.UserAgent = Request.UserAgent;

  8. Hi!
    Thanks for the solution.
    I’m trying to use it for all requests (JS, Images, XML).
    Unfortunately it’s not working…For example, I’m trying to get an image using the proxy, so I use the following URL


    but the browser does not recognize it as an image. The Content Type is correct. Any ideas?

  9. This is great thanks for sharing. With minor changes (accessing the Request object through context) I put this in an asynchronous HTTP handler for added efficiency and to support concurrency. I also updated a few things to support POST requests, as I do think this is worthwhile

    • Did you publish your modified code anywhere? What you added sounds exactly like what I thought was missing from this great post.

  10. Thanks this proxy works great, except for images. Any image that is requested will not show in a browser due to “The image … cannot be displayed because it contains errors.” If I request an image and then request it via the proxy the first request returns fine and the 2nd returns this error message. Any suggestions? In case you are wondering I do have a valid case for requesting images – I’m performance testing mapping services via ajax

  11. How would we use this in a SharePoint site? I added a page which resides in layouts and all I get an an error with no reason.

  12. Hi John,

    i have problem when i try to create a web service in C#.Net and call its webMethod with javaScript in .html file that is located on my desktop, the problem is when i tried to run it throw my IE webbrowser, it works with no issues, but on firefox and google chrome, the xhr.status = 0 and xhr.responseXML.xml is null,

    here is my html code :

    Premiere Application

    function resultat(){

    “use strict”;

    // alert(‘1′);

    var strRequest ;

    var xhr ;

    if(window.XMLHttpRequest) {

    try {

    xhr = new XMLHttpRequest();

    } catch(e) {

    xhr = false;


    } else if(window.ActiveXObject) {

    try {

    xhr = new ActiveXObject(“Msxml2.XMLHTTP”);

    } catch(e) {

    try {

    xhr = new ActiveXObject(“Microsoft.XMLHTTP”);

    } catch(e) {

    xhr = false;



    } (“POST”, “http://localhost/TemperatureWebService/Convert.asmx”,


    xhr.setRequestHeader( “Content-Type”,”text/xml; charset=utf-8″);


    “SOAPAction”, “”);

    // alert(‘3′);

    strRequest = “”;

    strRequest = strRequest + “”;

    strRequest = strRequest + ” “;

    strRequest = strRequest + “100”;

    strRequest = strRequest + “”;

    strRequest = strRequest + “”;

    // alert(strRequest);

    xhr.onreadystatechange = function () {

    // alert(xhr.readyState);

    // alert(xhr.status);

    if(xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)){

    //receiving response




    alert(‘result !’);






    catch(e) {

    // xhr = false;



    Application :




    and here is my web service : convert.asmx :

    using System;

    using System.Collections;

    using System.Linq;

    using System.Web;

    using System.Web.Services;

    using System.Web.Services.Protocols;

    using System.Xml.Linq;


    /// Description résumée de Convert


    [WebService(Namespace = “”)]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    // Pour autoriser l’appel de ce service Web depuis un script à l’aide d’ASP.NET AJAX, supprimez les marques de commentaire de la ligne suivante.


    public class Convert : System.Web.Services.WebService {

    public Convert () {

    //Supprimez les marques de commentaire dans la ligne suivante si vous utilisez des composants conçus




    public string HelloWorld() {

    return “Hello World”;



    public double FahrenheitToCelsius(double Fahrenheit)


    return ((Fahrenheit – 32) * 5) / 9;



    public double CelsiusToFahrenheit(double Celsius)


    return ((Celsius * 9) / 5) + 32;




    please help me, i think it is an issue of cross domain.. i tried several methods but in vain..

  13. Hi John,
    Is there any way to make this compatible with post requests as well? Also how would I integrate this solution into an MVC 4 web application?

  14. I know this is quite old, but I’ve tried to use it with “” and it doesn’t work. It just redirects to the gmail page and you are still on the gmail domain.

    • There is probably a redirect on that page itself. Nothing we can really do about that unless you want to scrape the page content and try to replace it before the page is returned by the proxy.



  1. [SharePoint 2010] Cross-Domain Proxy Page for Client-Side Scripts « SharePoint John – John Chapman's Blog About SharePoint, ASP.NET, C#, jQuery, SQL - [...] 2010] Cross-Domain Proxy Page for Client-Side ScriptsFollowing my blog post about ASP.NET Proxy Pages for Client-Side Scripts I have …

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Pin It on Pinterest

Share This