2

我有一个桌面应用程序,我在其中使用 CSOM 直接连接到 SharePoint Online 网站。现在的问题是这个请求必须通过代理服务器进行。到目前为止,我所做的是已将代理服务器设置传递给 ClientContext 的 ExecutingWebRequest 事件,包括凭据。但是,问题在于 SharePointOnlineCredentials 类。我必须设置 ClientContext 的凭据。当我将用户 ID 和密码传递给此类的构造函数时,它在内部向 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);

该代码预期在不需要任何身份验证的代理服务器上成功运行。这是我无法配置的 SharePointOnlineCredentials。我还尝试使用 NetworkCredentials 代替 SharePointOnlineCredentials。代码编译成功,但 SP 抛出 Forbidden 异常。

4

1 回答 1

1

您是否尝试过在 Web 配置文件中设置代理设置?例如:

  <system.net>
    <defaultProxy>
      <proxy
         usesystemdefault="False"
         proxyaddress="https://MyCompanyName.sharepoint.com/"
         bypassonlocal="True"

         />
    </defaultProxy>
  </system.net>

然后通过设置要连接的用户名覆盖您的代码。

此外,我很难跟踪导致您崩溃的代码行:ctx.Crednetials = new SP.SharePointOnlineCredentials(this.userName, passWord);

于 2014-09-03T18:08:09.960 回答