如何将代理凭据传递给SharePoint客户端上下文对象...? (SharePoint客户端对象模型)

8
我正在编写一个使用客户端对象模型访问SharePoint网站的应用程序,但我在代理服务器后面。
我调用...
ClientContext.ExecuteQuery()

当您遇到以下错误信息时...

远程服务器返回了一个错误:(407)需要代理身份验证。

如何将代理凭据传递给客户端上下文对象...?

3个回答

5
您需要将WebProxy(System.Net.WebProxy)对象传递给执行查询的WebRequest实例。一种方法是:
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();

编辑:修复了打字错误(ags --> args)


4

我认为你需要在<configuration>节点内的app.config中添加以下内容:

  <system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
  </system.net>

1
如果您的代理服务器不需要身份验证,请在您的app.config中尝试以下内容:
<system.net>
  <defaultProxy>
    <proxy
       usesystemdefault="False"
       proxyaddress="http://myproxyserver.company.com:8080"
       bypassonlocal="True"
     />
  </defaultProxy>
</system.net>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接