加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 04:11:49 所属栏目:asp.Net 来源:网络整理
导读:我试图提取一些我创建的SharePoint 2013列表数据,这些数据在我的机器上本地运行时运行正常,并且在本地运行一个服务器.在服务器上本地和本地运行时,我是用户相同的凭据.问题是,当我发布并导航到服务器上的ASP.NET应用程序时,我得到“远程服务器返回错误:(401
我试图提取一些我创建的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读