2012-06-19 70 views
1

如何使用C#获取SharePoint 2010中当前用户的GUID?以下是我的代码:如何在SharePoint 2010中获取当前的用户GUID?

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(); 
    } 

RawSid得不到正确的“数字”。

谢谢

回答

2

查看SPUser的会员。 根据需要,您应该使用ID属性或SidRawSid是二进制格式的用户的系统标识。

+0

对不起,我也测试了ID和SID。无法将这些ID保存为GUID格式 - > Guid userGuid = new Guid(currUser。???); – Rotaney

+0

为什么你需要它在GUID格式? –

+0

因为我喜欢GUID格式:-)我怎样才能得到UserGUID? – Rotaney

相关问题