(401) 使用客户端对象模型时出现未经授权的错误 [英] (401) Unauthorized Error working with Client Object Model

查看:79
本文介绍了(401) 使用客户端对象模型时出现未经授权的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从共享点站点检索文档库列表,这是我的代码,这是一个 Windows 应用程序

I'm tryiing to retrieve a list of document libraries from a sharepoint site, here is my code, this is a windows app

public string[] GetDocumentLibraries(ClientContext ctx)
    {
        Collection<string> libraries = new Collection<string>();
        try
        {
            //Getting the site from the SP context
            Web oWebsite = ctx.Web;
            write("INFO: SP site gotten");

            //Getting the list collection from the SP site
            write("INFO: Getting the list collection from the SP site");
            ListCollection listCollect = oWebsite.Lists;
            write("INFO: Loading the list");
            ctx.Load(listCollect);
            write("INFO: Getting the list");
            ctx.ExecuteQuery();
            write("INFO: List Collection size: " + listCollect.Count);

            //Getting the list of document libraries
            foreach (List docLibList in oWebsite.Lists)
            {
                if (docLibList.BaseTemplate == (int)ListTemplateType.DocumentLibrary)
                {
                    write("INFO: Document Library: " + docLibList.Title);
                    libraries.Add(docLibList.Title);
                }
            }
        }
        catch (Exception e)
        {
            write("ERROR: Error getting the list of document libraries, error detail " + e.Message + " " + e.StackTrace);
        }

        return libraries.ToArray();
    }

我曾在三个不同的 SharePoint 服务器中尝试过此代码,它在其中两个服务器中都有效,但在第三个中我遇到了此异常

I had tried this code in three different SharePoint servers, it works in two of them, but in the third one I'm getting this exception

ERROR: Error getting the list of document libraries, error detail The remote server returned an error: (401) Unauthorized.    at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
   at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
   at P_DocumentImporter.DocumentImporter.GetDocumentLibraries(ClientContext ctx)

而且我确定凭据是正确的,

And I'm sure the credentials are correct,

关于这方面的任何线索,

Any clue about this,

谢谢,

推荐答案

这个问题看起来很陈旧,但为了可能查看此问题的其他人的利益,只有可能的问题会导致此问题.

This question looks old but, for the benefit of others that might view this question, there are only possible issues that cause this.

  1. 登录凭据(丢失或不正确)
  2. 客户端和服务器之间的代理/防火墙不允许通信.

这篇关于(401) 使用客户端对象模型时出现未经授权的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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