如何将我的代理凭据传递给 SharePoint 客户端上下文对象...?(SharePoint 客户端对象模型) [英] How do I pass my proxy credentials to a SharePoint Client Context object...? (SharePoint Client Object Model)

查看:52
本文介绍了如何将我的代理凭据传递给 SharePoint 客户端上下文对象...?(SharePoint 客户端对象模型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用客户端对象模型访问 SharePoint 网站的应用程序,并且我在代理服务器后面.

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

我打电话...

ClientContext.ExecuteQuery()

并收到以下错误消息...

and receive the following error message...

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

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

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

推荐答案

您需要将 WebProxy (System.Net.WebProxy) 对象传递给执行查询的 WebRequest 实例.一种方法是

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();

修正错别字(ags --> args)

Fixed typo (ags --> args)

这篇关于如何将我的代理凭据传递给 SharePoint 客户端上下文对象...?(SharePoint 客户端对象模型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆