我试图拉取我创建的一些SharePoint 2013列表数据,当在我的机器上本地运行时和在服务器上本地运行时都正常工作。我使用相同的凭据在本地和服务器上运行。问题是当我发布并导航到我的ASP.NET应用程序时,我会遇到"The remote server returned an error: (401) Unauthorized." 的错误...
我看了很多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,但没有成功。我希望应用程序使用已登录用户的凭据而不是计算机的凭据...
以下是我使用的代码:
我看了很多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", 0, 1000);
EntityInstanceCollection items = entity.FindFiltered(filterCollection, filter, lobSystemInstance);
服务器正在运行 IIS 6.0。
欢迎提供任何建议!
谢谢!