0

I have made a restservice that combines data from different origins on a local environment. One of the origins is an onprem SharePoint 2019 where I need to use the rights from the user that accesses the restservice. I am using impersonation for that and if I debug from Visual Studio through IIS express it works fine.. but when I publish it to IIS it doesn't.

In the web.config I have added

<identity impersonate="true" />

And my test code is this..

            SPSecurity.RunWithElevatedPrivileges(delegate ()
            {
                using (WindowsImpersonationContext impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate())
                {
                    try
                    {
                        values.Add(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                        SPSite sPSite = new Microsoft.SharePoint.SPSite(ConfigurationManager.AppSettings["SPUrl"]);
                        values.Add(sPSite.RootWeb.CurrentUser.Name);
                        values.Add(sPSite.RootWeb.Title);
                    }
                    catch (Exception ex)
                    {
                        values.Add(ex.Message);
                    }
                }
            });

I just return an array of information and the values are

  • impersonated username - OK
  • the name of the current user - Ok
  • the title of the rootweb - access denied
  • error if it fails.. and it does.

We have tried to set spn on the server. But that's still not enough.

Burrhus
  • 156
  • 6

0 Answers0