HttpWebRequest Through Proxy Error - Server 2008 R2 RRS feed

  • Question

  • I am writing some inline code in a Sharepoint (WSS 3.0) Page that does a simple web request using a specified proxy. The Server that WSS is on is a Windows Server 2008 R2 running IIS 7.5.


    HttpWebRequest r = (HttpWebRequest)WebRequest.Create(url);
    WebProxy p = new WebProxy();
    p.Address = new Uri("http://proxyurl");
    p.UseDefaultCredentials = true;
    r.Proxy = p;
    HttpWebResponse resp = (HttpWebResponse)r.GetResponse();


    When I hit the page, I receive "System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse()". I assume this is coming from the proxy because if I remove p.UseDefaultCredentials = true;, I receive a 407 - Proxy Authentication required.

    If I try this same code on a Windows Server 2008 Standard server using IIS 7.0, it works fine and requires no further configuration.

    I went down the path of trying to make sure Delegation for the first server was set up correctly, but it was never set up for the second server yet works.

    Any help would be greatly appreciated!

    Some more information:

    If I remote to the Windows Server 2008 R2 machine, I can access the page and it works just great. Seems to be the credentials aren't passing through the 2008 R2 Server to the proxy. 

    But at the same time, no additional configuration of the 2008 Standard server was needed and it works no matter where you access the site from.

    • Edited by Mike Walsh FIN Wednesday, April 27, 2011 7:52 PM Some more information added. Was a "reply" within less than 20 mins from the OP. In such cases (with no replies in between) edit your original post
    Wednesday, April 27, 2011 7:18 PM

All replies

  • Hi Moboborson,


    It seems that the cause of 403 error was something wrong with the certificate. And I think what you did is right. For the error 407, I would like to suggest you make sure that the Account Used for Anonymous Access property of the virtual directory or Web site is set to a domain account. By default, this is set to a local account.


    Thanks & Regards,

    Peng Lei

    Thursday, April 28, 2011 2:31 AM
  • Peng,

    Thanks for your response. I probably shouldn't have even mentioned the 407 as I can control whether or not I get that. I was just including it to show I was getting past the need for Proxy authentication.

    I'm not sure about the Certificates. I never explicitly set anything up with the environment that works under Windows Server 2008 Standard. Would you be able to tell me what to check/look for?

    Thank you

    Thursday, April 28, 2011 1:51 PM