[英]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.