Monday, March 19, 2012

How to check if current user operates as System Account

While trying to find out a better way to check if current user operates as System Account, other then checking if the login name is “SHAREPOINT/system” string, I’ve stumbled upon SPSite.SystemAccount property.
So the problem is cut down to:
  • in event handlers
    1. web.Site.SystemAccount.ID == properties.CurrentUserId
  • in web pages or controls
    1. SPContext.Current.Web.CurrentUser.ID == SPContext.Current.Site.SystemAccount.ID
You can change SPContext.Current.Web with your SPWeb instance variable. Same goes for SPContext.Current.Site.

No comments: