About Web Part
I was working in a Claims enabled SharePoint Web Application, where I felt the need of a Claims Viewer component which can display the current claims of the logged-in user.
An example is displayed below:
![example]()
Web Part
The above component is developed as a Web part and requires a 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,
- Claim Type is the pre-defined URL
- Claim Value is the actual claim value eg: Windows\administrator
Note: You can use the References for articles on Installation of the Claims Viewer Web part.
Claims Viewer Web Part - Installation
Download
You can go to this link to get the Web part.
From there, choose the downloads page.
![page]()
You will get the WSP file.
![WSP]()
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 and open the PowerShell Window in administrator mode.
![Administrator mode]()
You will get the following command Window:
![command]()
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 snapshot:
![message]()
Now, run the following command to install the WSP package:
- Install-SPSoluton ClaimsViewerWebPart2013.wsp –gacdeployment –webapplication http://yourserver
If things went well, you will get the following output with no error messages:
Now, you can come to your SharePoint site > Go to Site Collection features > Activate the following feature:
![feature]()
Once you have activated the feature, you can add the Web Part to a page.
Create a new page and choose the Insert Web part option. You should be able to see the Claims Web part as shown below:
![web part]()
Insert the Web part & Save the page. You are ready to use the Claims Viewer Web part.
![web part]()
Note: Your claims may be different from the items shown above.
References
Summary: In this article, we have explored how to install the Claims Viewer Web part.