简体   繁体   English

通过客户端对象模型中的代理服务器连接到SharePoint Online

[英]Connect to SharePoint Online via proxy server in Client Object Model

I have a desktop application where I am using CSOM to connect to the SharePoint Online site directly. 我有一个桌面应用程序 ,我在其中使用CSOM直接连接到SharePoint Online网站。 The problem now is that this request has to be made through a proxy server. 现在的问题是必须通过代理服务器发出此请求。 What I have done so far is that I have passed the proxy servers settings, including the credentials to the ExecutingWebRequest event of the ClientContext. 到目前为止,我已经完成了传递代理服务器设置的操作,包括ClientContext的ExecutingWebRequest事件的凭据。 However, the problem is the SharePointOnlineCredentials class. 但是,问题出在SharePointOnlineCredentials类。 I have to set the Credentials of the ClientContext. 我必须设置ClientContext的凭据。 When I am passing the userID & password to the constructor of this class, it is internally making a request to SP to validate the credentials. 当我将userID和密码传递给此类的构造函数时,它在内部向SP发出请求以验证凭据。 Now, I am unable to set/pass the proxy id/password to this class which is why the proxy server is refusing the request I am getting an IdcrlException. 现在,我无法设置/将代理ID /密码传递给此类,这就是为什么代理服务器拒绝我收到IdcrlException的请求的原因。 Below is the sample code I am using as of now. 以下是到目前为止我正在使用的示例代码。

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

The code expectedly runs successfully on proxy servers which do not require any authentication. 该代码有望在不需要任何身份验证的代理服务器上成功运行。 It's this SharePointOnlineCredentials that I am not able to configure. 我无法配置的是此SharePointOnlineCredentials。 I have also tried to use NetworkCredentials in the place of SharePointOnlineCredentials. 我还尝试过使用NetworkCredentials代替SharePointOnlineCredentials。 The code compiles successfully but SP is throwing Forbidden exception. 代码编译成功,但是SP抛出了Forbidden异常。

Have you tried setting the Proxy Settings in the web config file? 您是否尝试过在Web配置文件中设置代理设置? For example: 例如:

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

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

Then override in your code by setting the username to connect with. 然后通过设置要连接的用户名覆盖代码。

Also I am having difficulty following where the line of code is that is crashing your: ctx.Crednetials = new SP.SharePointOnlineCredentials(this.userName, passWord); 我也很难跟踪导致您崩溃的代码行:ctx.Crednetials = new SP.SharePointOnlineCredentials(this.userName,passWord);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 c# 和客户端对象模型 (CSOM) 使用外部用户连接到 SharePoint Online - Connect to SharePoint Online using an external user using c# and Client Side Object Model (CSOM) 当我尝试使用SharePoint Client Object Model和.NET应用程序在线连接共享点时出现“提供了无效的参数”错误 - “An invalid argument was supplied” error when I try to connect sharepoint online using SharePoint Client Object Model with .NET application 使用客户端对象模型在线访问SharePoint-禁止的错误 - Access SharePoint online using client object model- Forbidden error 通过代理服务器进行SharePoint身份验证 - SharePoint authentication via a proxy server 通过 WebClient 连接到 Sharepoint 服务器 - Connect to Sharepoint server via WebClient Sharepoint客户端对象模型区域设置 - Sharepoint Client Object Model locale SharePoint Server对象模型和WCF - SharePoint Server Object Model and WCF 如何使用凭据连接到SharePoint列表使用客户端对象模型? - How to use credentials to connect to a SharePoint list using the Client Side Object Model? 使用客户端对象模型(CSOM)将多个用户添加到SharePoint Online文档库项目“人员或组”列 - Add multiple users to SharePoint Online document library item “Person or Group” column using Client Side Object Model (CSOM) 通过客户端对象模型在SharePoint中重命名文件时,如果两者之间有一个点,则会修剪文件名 - When renaming a file in SharePoint via client object model, the filename gets trimmed if there's a dot in between
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM