简体   繁体   中英

How to retrieve claims for current user in SharePoint 2013

How do I retrieve Claims for current user in SharePoint 2013?

In earlier version (SP 2010/.NET 3.5), I could have used the below code, but the Claims related APIs have changed in .NET 4.5. Thus, what is the .NET 4.5 way of achieving the same?

IClaimsPrincipal cp = Page.User as IClaimsPrincipal;
IClaimsIdentity ci = (IClaimsIdentity)cp.Identity;
foreach (Claim c in ci.Claims)
{
}

Try this:

 ClientContext clientContext =
                TokenHelper.GetClientContextWithAccessToken(
                    sharepointUrl.ToString(), accessToken);



        //Load the properties for the Web object.
        Web web = clientContext.Web;
        clientContext.Load(web);
        clientContext.ExecuteQuery();

        //Get the site name.
        siteName = web.Title;

        //Get the current user.
        clientContext.Load(web.CurrentUser);
        clientContext.ExecuteQuery();
        currentUser = clientContext.Web.CurrentUser.LoginName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM