When using SharePoint, sometimes you need to get the login name of the current logged-in user in the background, usually using SPContext.Current.Web.CurrentUser, but there is a special "System account", Get its real login name is a problem, get to the "domain name \system", Baidu has not found a good long time to find the results, the first time using the UserProfileManager way to obtain, but the user Profile Synchronization service is always a problem, have to find other ways.
Google a bit, found a way to get this user name, the following list I use the two ways, I do not know whether there is a more reliable way.
1, HttpContext.Current.User.Identity.Name;
This is the simplest method, specifically there are no other problems, have not been tested.
2, use UserProfileManager.
UserProfileManager myprofile = new UserProfileManager (context);
UserProfile user = Myprofile.getuserprofile (per. User.samaccountname);
We can get what we need in the user object.
This is more complicated, you need to reference some DLLs
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\isapi\ Microsoft.Office.Server.UserProfiles.dll
There are some dependencies when using UserProfileManager, and the user Profile Synchronization service must be started, which is a problem because there are a lot of times when this service will fail to start.
Get.
Get the real account for the system account in SharePoint 2010