Get the real account for the system account in SharePoint 2010

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.