无法通过客户端对象模型中的代理服务器连接到SharePoint Online [英] Unable to Connect to SharePoint Online via proxy server in Client Object Model

查看:71
本文介绍了无法通过客户端对象模型中的代理服务器连接到SharePoint Online的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CSOM的代码可以直接连接到SharePoint Online网站。现在的问题是该请求必须通过代理服务器进行。到目前为止我所做的是我已经将代理服务器设置(包括凭证
)传递给ClientContext的ExecutingWebRequest事件。但是,问题是SharePointOnlineCredentials类。我必须设置ClientContext的凭据。当我传递userID&这个类的构造函数的密码,它在内部
向SP发出请求以验证凭据。现在,我无法设置/传递代理ID /密码到这个类,这就是代理服务器拒绝请求我得到IdcrlException的原因。下面是我现在使用的示例代码。



I have the code for CSOM to connect to the SharePoint Online site directly. 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. However, the problem is the SharePointOnlineCredentials class. I have to set the Credentials of the 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. 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. 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);




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


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. I have also tried to use NetworkCredentials in the place of SharePointOnlineCredentials. The code compiles successfully but SP is throwing Forbidden exception.

推荐答案

有点晚了,但我想知道同样的事情并认为我会分享对我有用的东西。

A bit late, but I was wondering the same thing and thought I would share what worked for me.

来源: 
http://jpd.ms/powershell-office-365-authenticated-代理/

Source:  http://jpd.ms/powershell-office-365-authenticated-proxies/

干杯! : - )

var securePassword = new SecureString();
"sharepoint password".ToList().ForEach(securePassword.AppendChar);
var ctx = new ClientContext("https://sharepoint site") { Credentials = new SharePointOnlineCredentials("sharepoint UPN", securePassword) };
ctx.ExecutingWebRequest += (s, e) =>
{
	e.WebRequestExecutor.WebRequest.Proxy.Credentials = new NetworkCredential("proxy username", "proxy password");
	//OR
	e.WebRequestExecutor.WebRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
};
var web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();


这篇关于无法通过客户端对象模型中的代理服务器连接到SharePoint Online的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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