1
votes

I'm using the SPSecurity.RunWithElevatedPrivileges.... allow to "impersonate" the super user "sharepoint\system" account.

Is the "sharepoint\system" account is an alias of the app pool identity of the current web application?

So if my app pool identity is a custom user (with email and other information), how can i retrieve its information? (the information i'm trying to get is the email address...the custom app pool user email has a value, the "sharepoint\system" account email has no value!!!)

I also tried to retrieve the appPool identity by using the WindowsIdentity.Impersonate(IntPtr.Zero) method but...nothing!

So any ideas????

1

1 Answers

2
votes

Points to note:

  • The code that runs in the SPSecurity.RunWithElevatedPrivileges delegate method runs under the SharePoint\System account
  • SharePoint\System account has super user privileges. However it is recognized within the SharePoint run time environment but not by the windows security system, i.e. it doesn't represent the account under which the AppPool is running
  • When tried to access the resources outside the SP Environment such as Server File system/ DB then only the AppPool Identity comes into picture
  • If you want to access the e-mail address of the user account under which the AppPool is running, you may try...

    SPSecurity.RunWithElevatedPrivileges(delegate {
            using (SPSite siteCollection = new SPSite("Url"))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    Console.WriteLine(string.Format("Current Logged in User is {0}. And Email Id: {1} ", site.CurrentUser.LoginName ,site.CurrentUser.Email));
                    appPoolAccount = siteCollection.WebApplication.ApplicationPool.Username;
                    SPUser appPoolUser = site.Users[appPoolAccount] as SPUser;
                    Console.WriteLine(string.Format("AppPool User is {0}. And Email Id: {1} ", appPoolUser.LoginName, appPoolUser.Email));
                    Console.ReadKey();
                }
            }
        });
    
  • The output will look like... enter image description here
  • So If you really want to get the EmailId of the AppPool account, pick the user explicitly and access the Email property of the SPUser object as I did above..