远程服务器返回错误:(401)未经授权.在ASP.NET中使用CSOM

我试图提取一些我创建的SharePoint 2013列表数据,这些数据在我的机器上本地运行时运行正常,并且在本地运行一个服务器.在服务器上本地和本地运行时,我是用户相同的凭据.问题是,当我发布并导航到服务器上的ASP.NET应用程序时,我得到“远程服务器返回错误:(401)未经授权.”错误

我查看了stackoverflow上的一些帖子以及网络上的其他一些文章

这指出上下文似乎正在使用IUSR:
http://blogs.msdn.com/b/sridhara/archive/2014/02/06/sharepoint-2013-csom-call-from-web-part-fails-with-401-for-all-users.aspx

这个提到尝试设置认网络凭据:
https://sharepoint.stackexchange.com/questions/10364/http-401-unauthorized-using-the-managed-client-object-model

我已经尝试使用文章中提到的修复程序以及尝试强制上下文使用DefaultNetworkCredentials但没有运气.我想让应用程序使用登录用户的凭据而不是机器…

这是我正在使用的代码

SP.ClientContext context = new SP.ClientContext("MySPDevInstance");
        context.Credentials = CredentialCache.DefaultNetworkCredentials;

        Entity entity = context.Web.GetEntity(collectionNamespace,collectionName);
        LobSystem lobSystem = entity.GetLobSystem();
        LobSystemInstanceCollection lobSystemInstanceCollection = lobSystem.GetLobSystemInstances();

        context.Load(lobSystemInstanceCollection);
        context.ExecuteQuery();

        LobSystemInstance lobSystemInstance = lobSystemInstanceCollection[0];
        FilterCollection filterCollection = entity.GetFilters(filter);

        filterCollection.SetFilterValue("LimitFilter",1000);

        EntityInstanceCollection items = entity.FindFiltered(filterCollection,filter,lobSystemInstance);

服务器正在运行IIS 6.0

任何建议将不胜感激!

谢谢

解决方法

我假设您的ASP.NET网站正在使用Windows集成(NTLM)身份验证.以这种方式进行身份验证的用户无法从服务器端(Web服务器)向第二个位置进行身份验证.您遇到了所谓的NTLM的“双跳”(1)限制.您必须在服务器端使用专用帐户,或者如果您确实要使用登录用户的身份,则必须使用允许委派的身份验证方案,例如Kerberos.

如果您确实需要用户的身份来访问SharePoint数据而您无法更改身份验证方案,那么最好的方法是使用JavaScript CSOM.这意味着用户直接对SharePoint服务器进行身份验证(单跳,而不是双重),并且ASP.NET站点用户提供包含此脚本的页面.

(1)http://blogs.msdn.com/b/knowledgecast/archive/2007/01/31/the-double-hop-problem.aspx

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...