Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint / SharePoint2013

SharePoint 2013 Claims Viewer Web Part

5.00/5 (1 vote)
30 Jun 2016CPOL2 min read 15.9K  
In this article we can explore the Claims Viewer Web Part.

About Web Part

I was working in a Claims enabled SharePoint Web Application where I felt the need of a Claims Viewer component which could display the current claims of the logged-in user.

An example is displayed below.

Image 1

Web Part

The above component is developed as a Web Part and requires Farm Solution for deployment. The C# code runs in the server-side and renders the claims values to the output.

Code

Following is the code which retrieves the claims.

protected void Page_Load(object sender, EventArgs e)
        {
            IClaimsPrincipal principal = Thread.CurrentPrincipal as IClaimsPrincipal;
            IClaimsIdentity identity = principal.Identity as IClaimsIdentity;
 
            IList<ClaimEntity> list = new List<ClaimEntity>();
 
            foreach (Claim claim in identity.Claims)
                list.Add(new ClaimEntity()
                {
                    ClaimType = claim.ClaimType,
                    Value = claim.Value,
                    ValueType = claim.ValueType
                });
 
            RefreshGrid(list);
        }

Once the user is logged in, the thread will contain the Claims Principal object. We can get the Claims from this object.

Each claim will have the following:

Image 2
You can use the References for articles on Installation of the Claims Viewer web part.

Download

You can go the following location to get the web part. It is Free!

https://sharepoint2013claimsviewer.codeplex.com/

From there choose the Downloads page:

Image 3

You will get the WSP file.

Image 4

The web part is Free for development & commercial use.

Installation

Once you have downloaded the WSP file, you need to install it. This is a Farm Solution so you require PowerShell.

Go to your SharePoint Server & Open the PowerShell window in Administrator mode.

Image 5

You will get the following command window.

Image 6

Run the following command to add the WSP package to Farm Solutions.

  • Add-SPSolution "full path"
  • Eg: Add-SPSolution "c:\shared\ ClaimsViewerWebPart2013.wsp"

If things went well, you will get the following message.

Image 7

Now run the following command to install the WSP package.

  • Install-SPSoluiton ClaimsViewerWebPart2013.wsp –gacdeployment –webapplication http://yourserver

If things went well, you will the following output with no error messages.

Image 8

Now you can come to your SharePoint site > Go to Site Collection features > Activate the following feature.

Image 9

 

Once you have activated the feature, you can add the Web Part to a page.

Create a new page & choose the Insert web part option. You should be able to see the Claims web part as shown below.

Image 10

Insert the web part & Save the page. You are ready to use the Claims Viewer web part.

Image 11

Image 12

Your claims may be different from the items shown above.

References

https://sharepoint2013claimsviewer.codeplex.com/

Summary

In this article we have explored about a Free SharePoint 2013 Claims Viewer web part.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)