问题
How can I get the GUID of the current user in SharePoint 2010 with C#? The following is my code:
public string readAndEncodeGUID()
{
Guid userGuid = Guid.Empty;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb readWeb = SPContext.Current.Web;
SPUser currUser = SPContext.Current.Web.CurrentUser;
userGuid = new Guid(currUser.RawSid);
});
//Variable = encode USER-GUID
return userGuid.ToString();
}
The RawSid get not the right "number".
thanks
回答1:
Check out the SPUser members.
You should use either the ID
property or the Sid
depending on what you want.
RawSid
is the system ID of the user in binary format.
来源:https://stackoverflow.com/questions/11099550/how-can-i-get-the-current-user-guid-in-sharepoint-2010