How can I get the current user-GUID in SharePoint 2010?

房东的猫 提交于 2020-01-06 03:56:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!