【问题标题】:Connecting with sharepoint site using CSOM使用 CSOM 与 sharepoint 站点连接
【发布时间】:2014-12-10 05:21:19
【问题描述】:

我的代码如下所示

  try
    {

        string strUserName="abc";
        string strPassword="123";
        ClientContext context = new ClientContext(siteurl);
        var credentials = new NetworkCredential(strUserName, strPassword,"Ext");


        context.Credentials = credentials;
        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();

        // Now, the web's properties are available and we could display 
        // web properties, such as title. 
        System.Console.WriteLine("Web Title");
        System.Console.WriteLine(web.Title);
    }
    catch (Exception ex)
    {
    }

报错“无法连接远程服务器”

【问题讨论】:

  • 猜测您的用户名没有足够的权限访问该站点。您可以检查您的详细错误信息及其调用堆栈以获取线索
  • 它有权限,当我从浏览器访问时,我可以使用这些凭据进行访问。从 c# 给出的错误“远程证书根据验证过程无效,无法为 ssl/tls 安全通道建立信任关系”
  • 我的电脑上没有安装共享点。您已检查过您的共享点日志?此错误消息可能与您的客户端和共享点之间的证书验证有关
  • siteurl的值是多少?

标签: c# sharepoint csom


【解决方案1】:

首先确保正确传递以下实体:

  • 网站网址
  • strUserName
  • strPassword
  • “分机”

如果您尝试连接到 SharePoint Online 2013,则必须将“NetworkCredential”替换为“SharePointOnlineCredentials”。这是它的代码 sn-p:

    string strUserName="abc";
    string strPassword="123";
    SecureString ssPwd = new SecureString();
    strPassword.ToList().ForEach(ssPwd.AppendChar);
    ClientContext context = new ClientContext(siteurl);
    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, ssPwd);

    context.Credentials = credentials;
    // The SharePoint web at the URL.
    Web web = context.Web;

    // We want to retrieve the web's properties.
    context.Load(web);

    // Execute the query to the server.
    context.ExecuteQuery();

【讨论】:

  • 它不在 sharepoint 2013 上。它给出了详细异常“远程证书根据验证过程无效,无法为 ssl/tls 安全通道建立信任关系”
【解决方案2】:

接受自签名证书:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

【讨论】:

    猜你喜欢
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2022-11-24
    • 2020-08-10
    • 2019-07-26
    • 2017-09-16
    相关资源
    最近更新 更多