views:

41

answers:

0

Hi,

I’m having some permission denied issues when I try to execute following code segment within the context of a SharePoint domain user. Please note that this particular user does not belong to any groups in the local machine. I have tried to run the following code by adding this user as “reader” and “administrator” of the SharePoint but in both cases I got the “System.UnauthorizedAccessException”.

Then I tried by adding this particular user to the “Administrators” group on the local machine and it worked! Unfortunately this is not an option in my case.

So what minimum permissions do I need in both SP and Local computer ends to successfully execute the below code segment.

WindowsImpersonationContext ctx = CreateIdentity("user", "AD", "password").Impersonate();

SPGlobalAdmin spGlobalAdmin = null; SPVirtualServer virtualServer = null;

try { spGlobalAdmin = new SPGlobalAdmin(); virtualServer = spGlobalAdmin.OpenVirtualServer(new Uri("http://spserver")); Console.WriteLine(virtualServer.Sites[0].Url); } catch(Exception e) { } ctx.Undo();

Also please note that I'm running the above code segement on one of the front end servers itself.

Thanks, Shamika