现在阅读
SharePoint 2013 Claims Viewer Web Part
0

SharePoint 2013 Claims Viewer Web Part

由 ultracpy2018年1月26日

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.

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:


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:

You will get the WSP file.

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.

You will get the following command window.

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.

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.

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

 

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.

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

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.

出处:https://www.codeproject.com/Articles/1109905/SharePoint-Claims-Viewer-Web-Part

关于作者
ultracpy
评论

    你必须 登录 提交评论