Thursday, September 23, 2010

Building a claims viewer webpart for SharePoint 2010

When running through the MSDN article – Claims Walkthrouhgh: writing claims providers for SharePoint 2010 – I noticed that it did not clearly showed how the webparts where build which showed the overview of the claims for a specific request. Reza pointed me in the correct direction by sending me the link to a post from Steve Peschka (a must read blog for people who work with SharePoint and claims) – Figuring out what claims you have in SharePoint 2010.

Some things you should know when you try to build a claims viewer webpart of your own:

The code is actually pretty simple – you can use a Visual Web Part (new in 2010) or a standard webpart – here’s a snippet

IClaimsPrincipal cp = Page.User as IClaimsPrincipal;   
if (cp != null) {
IClaimsIdentity ci = (IClaimsIdentity)cp.Identity;
foreach (Claim c in ci.Claims) {
sb.Append(c.ClaimType + " " + c.Value + "<br>");

Have fun ….

1 comment:

Prakash Madheswaran said...

how to display claims of other user?? like as a admin i want to see other user claims