Category Archives: Uncategorized

Last post….

Hi,

Unfortunately, I’ll no longer post on this blog. I’ve refocused my career on a different direction and I’m no longer working directly with SharePoint. I’ll leave the blog up and running for now since I still can help some people with some SharePoint issues.

Yours,

Andy.

SPWeb.CurrentUser returns SHAREPOINT\System not the real user name.

If you try to get the current user login name or name in SharePoint and if it shows SHAREPOINT\System account, that’s because the current logged user is an admin account and is probably the one used in the application pool of the site. Also, you are probably getting the current user from an elevated SPWeb inside a RunWithElevatedPrivileges code. You can use the snippet below to get the real user:


SPWeb site = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
  using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
  {
    using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID))
    {
      //Don't use the ElevatedSite.CurrentUser
      string currUser = site.CurrentUser;
    }
  }
});

This will show the real login name instead of SHAREPOINT\System

Bear in mind that the code above is just a snippet and to show you the idea. Please make sure you use the SharePoint best practices coding for disposing objects when using the snippet above.

Hope that helps !