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
- Open Visual Studio.
- Open New Project dialog box. Expand Office/SharePoint node and choose SharePoint Solutions.
![]()
- Choose SharePoint 2013 – Empty Project template. Name the project as ClaimProviderProject.
![]()
- Choose Deploy as a farm solution option button and choose Finish button.
![]()
- To create a custom claims provider class file, right click ClaimProviderProject project -> Add -> New Item.
![]()
- Add the class file and name it as CustomClaimsProvider.cs.
![]()
- Complete the implementation of custom claims provider class by overriding the SPClaimProvider properties and methods.
- Build and deploy the solution to the site.
- 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.
- Check, if the custom Claims Provider is populated in assigning the permission to an item.
![]()
Create Claims Viewer WebPart
- To create a ClaimsViewer WebPart, right click on ClaimProviderProject project -> Add -> New Item.
![new]()
- Choose Visual Web Parts under Office/SharePoint node.
![Visual Web Parts]()
- Add ASP GridView control in ClaimsViewer.ascx file.
- <asp:GridView ID="gridClaims" runat="server"></asp:GridView>
![code]()
- Add Microsoft.IdentityModel reference to the project.
![reference]()
- Write the function, given below, inside the page load event receiver of the ClaimsViewer Webpart to get the claims of SharePoint portal.
- IClaimsPrincipal cp = Page.User as IClaimsPrincipal;
- if (cp != null) {
- IClaimsIdentity ci = (IClaimsIdentity) cp.Identity;
- gridClaims.DataSource = ci.Claims;
- gridClaims.DataBind();
- }
![reference]()
- Add this Webpart to our SharePoint page.
- 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.