Create Claims Viewer Webpart In SharePoint 2013 Using C# Server-Side Object Model

Introduction

A custom claims provider issues claims and package claims into security tokens, which can be used to give permission to the items in a customized way. Claims augmentation enables an Application to augment additional claims into the user token. Claims can be displayed in the people picker control through claims picking. In this article, I will explain, how to create Claims Viewer Webpart in SharePoint 2013 , using C# Server-Side Object Model.

Pre-Requisites

  1. Open Visual Studio.
  2. Open New Project dialog box. Expand Office/SharePoint node and choose SharePoint Solutions.



  3. Choose SharePoint 2013 – Empty Project template. Name the project as ClaimProviderProject.



  4. Choose Deploy as a farm solution option button and choose Finish button.



  5. To create a custom claims provider class file, right click ClaimProviderProject project -> Add -> New Item.



  6. Add the class file and name it as CustomClaimsProvider.cs.



  7. Complete the implementation of custom claims provider class by overriding the SPClaimProvider properties and methods.
  8. Build and deploy the solution to the site.
  9. Activate the custom Claims Provider, using Windows PowerShell script.

    • Set the IsEnabled to True for the Claim Provider.
    • Add provider association to the Web Application.

  10. Check, if the custom Claims Provider is populated in assigning the permission to an item.

Create Claims Viewer WebPart

  1. To create a ClaimsViewer WebPart, right click on ClaimProviderProject project -> Add -> New Item.

    new

  2. Choose Visual Web Parts under Office/SharePoint node.

    Visual Web Parts

  3. Add ASP GridView control in ClaimsViewer.ascx file.
    1. <asp:GridView ID="gridClaims" runat="server"></asp:GridView>   
    code

  4. Add Microsoft.IdentityModel reference to the project.

    reference

  5. Write the function, given below, inside the page load event receiver of the ClaimsViewer Webpart to get the claims of SharePoint portal.
    1. IClaimsPrincipal cp = Page.User as IClaimsPrincipal;  
    2. if (cp != null) {  
    3.     IClaimsIdentity ci = (IClaimsIdentity) cp.Identity;  
    4.     gridClaims.DataSource = ci.Claims;  
    5.     gridClaims.DataBind();  
    6. }  
    reference

  6. Add this Webpart to our SharePoint page.
  7. Open Webpart page and it will show all the Claims added to our SharePoint portal.

    portal

Summary

Thus, you have learned, how to create Claims Viewer Webpart in SharePoint 2013,  using C# Server-Side Object Model.