9

我试图提取一些我创建的 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", 0, 1000);

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

服务器正在运行 IIS 6.0

任何建议将不胜感激!

谢谢

4

4 回答 4

6

我假设您的 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

于 2014-04-03T18:06:36.600 回答
4

使用默认凭据为我工作:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.UseDefaultCredentials = true;
于 2015-10-07T10:37:35.437 回答
3

通过代码设置凭据:

SP.ClientContext context = new SP.ClientContext("MySPDevInstance");
context.Credentials = new NetworkCredential("username", "password");

您应该将其放在配置文件中以更改它,而无需发布或重新编译应用程序。

于 2014-04-03T17:57:08.307 回答
0

只是为了添加我遇到的另一个设置。如果该帐户被限制为只能访问某些服务器,那么也将客户端计算机添加到该帐户。例如,如果 Web 应用程序托管在服务器 A 上并尝试使用帐户 ABC 连接到服务器 B 上的 SharePoint 2010,则确保该帐户有权访问 Active Directory 中的服务器 A。通常 AD 帐户没有连接到机器的限制,但在我的情况下,该帐户仅限于某些机器。我将我的 Web 应用程序托管服务器添加到该帐户并且它工作正常。

于 2016-01-04T23:58:16.063 回答