通过客户端对象模型中的代理服务器连接到SharePoint Online
本文关键字:连接 SharePoint Online 代理服务器 过客 客户端 对象模型 | 更新日期: 2023-09-27 18:10:52
我有一个桌面应用程序,我使用CSOM直接连接到SharePoint Online网站。现在的问题是,这个请求必须通过代理服务器发出。到目前为止,我所做的是将代理服务器设置传递给ClientContext的ExecutingWebRequest事件,包括凭据。然而,问题是sharepointonlinecredals类。我必须设置ClientContext的凭据。当我传递userID &将密码传递给该类的构造函数,则在内部向SP发出验证凭据的请求。现在,我无法设置/传递代理id/密码到这个类,这就是为什么代理服务器拒绝请求,我得到一个IdcrlException。下面是我现在使用的示例代码。
SecureString passWord = new SecureString();
password.ToList().ForEach(passWord.AppendChar);
SP.ClientContext ctx = new SP.ClientContext(targetURL);
ctx.ExecutingWebRequest += (sen, args) =>
{
System.Net.WebProxy myProxy = new System.Net.WebProxy();
myProxy.Address = new Uri(this.proxyUrl);
myProxy.Credentials = new System.Net.NetworkCredential(this.proxyUserName, this.proxyPassword);
args.WebRequestExecutor.WebRequest.Proxy = myProxy;
};
//This is the line which is causing the issue.
ctx.Credentials = new SP.SharePointOnlineCredentials(this.userName, passWord);
代码预期在不需要任何身份验证的代理服务器上成功运行。这是我无法配置的sharepointonlinecredals。我还尝试在sharepointonlinecredals的位置使用NetworkCredentials。代码编译成功,但SP抛出Forbidden异常。
您是否尝试在web配置文件中设置代理设置?例如:
<system.net>
<defaultProxy>
<proxy
usesystemdefault="False"
proxyaddress="https://MyCompanyName.sharepoint.com/"
bypassonlocal="True"
/>
</defaultProxy>
</system.net>
然后在代码中通过设置要连接的用户名来重写。
我也有困难以下的代码行是崩溃你的:ctx。credential = new sp . sharepointonlinecrecredals(此。用户名、密码);