2

In a Windowsservice with a delegated Windowsidentity we access Sharepoint 2016 or 2019 by using the Sharepoint server object model (SSOM) located in the "Microsoft.SharePoint.dll". The Windowsservice is running .NET 4.5.1 and SharePoint is in claims based mode. The code that access SharePoint looks like following:

   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);
       }
   }

The windows users are impersonated and the SharePoint objects are created. This works fine for the Siteadministrator which is a regular windows user. If the impersonated user is another domain user f.ex. called "domain\user1" the access to SharePoint is not allowed. SharePoint knows the "domain\user1" as a windows claims user like "i:0#.w|domain\user1". So how do we make a context switch that can represent windows user "domain\user1" as "i:0#.w|domain\user1" to access sharepoint server side objects ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.