How do I pass my proxy credentials to a SharePoint Client Context object...? (SharePoint Client Object Model)
Asked Answered
K

3

8

I'm writing an application that accesses a SharePoint site using the Client Object Model and I'm behind a proxy server.

I call...

ClientContext.ExecuteQuery()

and receive the following error message...

The remote server returned an error: (407) Proxy Authentication Required.

How do I pass my proxy credentials to the Client Context object...?

Koon answered 11/11, 2010 at 5:52 Comment(0)
B
5

You will need to pass the WebProxy (System.Net.WebProxy) object to the WebRequest instance executing your query. One way of doing this is

ClientContext context = new ClientContext("<a valid url>");
context.ExecutingWebRequest += (sen, args) =>
{
  WebProxy myProxy = new WebProxy();
  myProxy.Address = new Uri("http://<proxy_server_address>");

  myProxy.Credentials = new System.Net.NetworkCredential("jack_reacher","<password>", "<domain>");
  args.WebRequestExecutor.WebRequest.Proxy = myProxy;
};
context.ExecuteQuery();

Edit: Fixed typo (ags --> args)

Boulder answered 11/1, 2013 at 6:44 Comment(0)
P
4

I think you need the following in your app.config inside the <configuration> node:

  <system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
  </system.net>
Penrod answered 11/11, 2010 at 15:5 Comment(0)
C
1

Try this in your app.config if your proxy server doesn't require authentication:

<system.net>
  <defaultProxy>
    <proxy
       usesystemdefault="False"
       proxyaddress="http://myproxyserver.company.com:8080"
       bypassonlocal="True"
     />
  </defaultProxy>
</system.net>
Cordwainer answered 12/3, 2015 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.