Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...?

like image 678
Sambo Avatar asked Nov 11 '10 05:11

Sambo


1 Answers

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)

like image 170
Karthik Avatar answered Oct 24 '22 15:10

Karthik