首页 > 解决方案 > 如何从 windowsidentity 上下文切换到代表 sharepoint windowsclaims 用户的上下文

问题描述

在具有委派 Windows 身份的 Windows 服务中,我们使用位于“Microsoft.SharePoint.dll”中的 Sharepoint 服务器对象模型 (SSOM) 访问 Sharepoint 2016 或 2019。Windowsservice 正在运行 .NET 4.5.1,SharePoint 处于基于声明的模式。访问 SharePoint 的代码如下所示:

   using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
   {
       using (SPSite archive = new SPSite(siteId))
       using (SPWeb workArea = archive.OpenWeb(webId))
       {
           SPList list = workArea.Lists[listId];
           SPFile spFile = RetrieveSPFileFromSPList(list, fileId);
       }
   }

模拟 Windows 用户并创建 SharePoint 对象。这适用于作为普通 Windows 用户的站点管理员。如果模拟用户是另一个域用户 f.ex。名为“域\用户 1”的访问 SharePoint 是不允许的。SharePoint 知道“domain\user1”作为 Windows 声明用户,例如“i:0#.w|domain\user1”。那么我们如何进行上下文切换,将 Windows 用户“domain\user1”表示为“i:0#.w|domain\user1”以访问共享点服务器端对象?

标签: sharepointclaims-based-identity

解决方案


推荐阅读