Partilhar via


Web Part to view a User’s Claims

As promised in my earlier video demo, here is a web part that I quickly wrote to view the claims of a user when they are authenticating to the SharePoint site using a Security Token Service such as Geneva Server. There are some important sections in the code. First is the check to see if a user is actually has a claims principal:

IClaimsPrincipal icp = null;
IClaimsIdentity claimsIdentity = null;

public ViewClaimsWebPart()
{
try
{
icp = this.Context.User as IClaimsPrincipal;
claimsIdentity = (IClaimsIdentity)icp.Identity;
}
catch
{
}
}

protected override void CreateChildControls()
{
try
{

           if (claimsIdentity != null)

 

And then just collecting the claims into a dataset:

ClaimsInfo oData = new ClaimsInfo();

foreach (Claim claim in claimsIdentity.Claims)
{
oData.Claims.AddClaimsRow(claim.ClaimType, claim.Value);
}

Here is a link where you can download the sample. Just be mindful it is a sample.

https://cid-601cfa765e7a6fd3.skydrive.live.com/self.aspx/Public/ViewClaimsWP.zip

 

Just one note that this project was built using the new Visual Studio Extensions for WSS 1.3 March CTP. You can get that here if you haven’t tried it out. Much better than previous releases – so give it a try.

https://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=fb9d4b85-da2a-432e-91fb-d505199c49f6

Comments

  • Anonymous
    August 05, 2009
    The comment has been removed