使用Microsoft.SharePoint.Client获取“ 400错误的请求”以获取自签名证书

时间:2018-10-28 06:28:11

标签: c# ssl sharepoint self-signed csom

从公司网络中加载时,我有一个SharePoint网站,它会加载一个自签名证书,该证书已在公司浏览器中列入白名单。从互联网加载的同一站点将具有经过验证的签名证书。

我的问题是,当我在公司网络中执行以下代码时,它会抛出400 Bad request
但是,可以按预期在Internet上执行此操作。

static void Main(string[] args)
{
    try
    {
        ClientContext publishingContext = new ClientContext("https://company.sharepoint.com/sites/test");
        SecureString securePassword = Utilities.GetSecurePassword("PASSWORD");
        publishingContext.Credentials = new SharePointOnlineCredentials("username@company.onmicrosoft.com", securePassword);
        List oList = publishingContext.Web.Lists.GetByTitle("Pages");
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>1519</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>";
        ListItemCollection collListItem = oList.GetItems(camlQuery);
        publishingContext.Load(collListItem);
        publishingContext.ExecuteQuery(); // Gives 400 Bad Request here...
        // Do something with collListItem
    } 
    catch(Exception ex) 
    {
        Console.WriteLine(ex);
    }
}

我认为这与Visual Studio(.Net Framework或Microsoft.SharePoint.Client.dll lib)不喜欢自签名证书有关。因此,我在公司网络中下载了要加载的证书,并将其安装在我的计算机上。这也没有帮助。

使用Microsoft.SharePoint.Client.dll库连接到使用自签名证书托管的SharePoint时,是否会遇到类似的问题?

0 个答案:

没有答案