kamagra how much to take

Your First InfoCard WebPart (CardSpace WebPart Example)

As discussed in a previous post, I was talking about a current client I am working with where we developed a bunch of ASP.NET 2.0 WebParts that are related to InfoCard management and provisioning used within SharePoint 2007. Some of this WebParts were strictly for interrogating the InfoCard properties in order to understand what was really going on beyond the scenes with SharePoint and InfoCard interaction. There are a bunch of ways to display the things that InfoCard is doing (such as claims), but there were some very specific things that I was interested in that I wanted to display in SharePoint that revolved around trying to understand what properties where doing what, claim interaction, etc. etc. etc.

Obviously, if you aren’t using CardSpace for your ASP.NET 2.0 Web Applications, this code is not going to prove real helpful. The code itself is very, very simplistic, since we are just going to be showing the associated claims. Within this, we are also going to include the PPID of the user since it is what really uniquely identifies the user. We have talked about the PPID before, it is unique in that it is a hash resulting from a calculation of the issued  certificate as well as a unique attribute about the user.

My intention in this post is to introduce SharePoint developers to working with InfoCard objects / the Identity Model’s API’s for the first time, which hopefully leads to amazing development initiatives all over the world :-) The CardSpace controls are a little bit more complex than this example, but this was just for fun on an afternoon.

The first thing that we have to do is establish the appropriate using directives, we are going to be using the System.IdentityModel.Claims and Microsoft.IdentityModel.TokenProcessor namespaces, in the code so that we can tap into the OM that will provide us with the CardSpace insight we desire. You will also need to establish the references in the Visual Studio.NET assemblies since they will provide the appropriate OM access we need.. We are also going to use the TokenProcessor class , which is available with the CardSpace SDK as sample code. The TokenProcessor class is responsible for the decryption and verification of the security token, which we are going to have to do in this WebPart as we are going to be working with the related claims.

  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Web.UI;
  4. using System.Xml.Serialization;
  5. using System.Web.UI.WebControls;
  6. using System.Web.UI.WebControls.WebParts;
  7. using System.IdentityModel.Claims;
  8. using Microsoft.IdentityModel.TokenProcessor;

Once the references are established for the WebPart, we can get started on the WebPart code.
Firstly, ensure that the master class file is inheriting from the System.Web.UI.WebControls.WebParts.WebPart base class so that this can be rendered within a SharePoint environment.

  1. public class ClaimInterrogationWebPart : WebPart

I am going to be displaying the token values through the use of a ASP.NET Label controls, its just easier since they have a text property that is easy to assign.

  1. private Label lblGivenName;
  2. private Label lblEmailAddy;
  3. private Label lblPPID;

I am going to setup some of the default behavior of the WebPart within the WebPart class constructor. This is not required by any means.

  1. // Set some of the default WebPart beahvior in the Webpart class constructor
  2. public ClaimInterrogationWebPart()
  3. {
  4. this.ExportMode = WebPartExportMode.All;
  5. this.ChromeState = PartChromeState.Normal;
  6. this.ChromeType = PartChromeType.None;
  7. this.AllowClose = true;
  8. this.AllowEdit = true;
  9. this.AllowMinimize = true;
  10. }

Our WebPart is going to get access to the related claims that are included in a token. Therefore, we are going to have to use the Claims property in order to pool the claims values. Then, we can use the Claims property for an indexed Claim accessor to get the Given Name, Email, and PPID of the user.

  1. protected override void  CreateChildControls()
  2. {
  3. base.CreateChildControls();
  4. string xmlToken;
  5. xmlToken = Page.Request.Params["xmlToken"];
  6. Token token = new Token(xmlToken);
  7. this.lblGivenName = new Label();
  8. lblGivenName.Text = token.Claims[ClaimTypes.GivenName];
  9. this.Controls.Add(lblGivenName);
  10. this.lblEmailAddy = new Label();
  11. lblEmailAddy.Text = token.Claims[ClaimTypes.Email];
  12. this.Controls.Add(lblEmailAddy);
  13. this.lblPPID = new Label();
  14. lblPPID.Text = token.Claims[ClaimTypes.PPID];
  15. this.Controls.Add(lblPPID);
  16. }

Lastly, in the render method just make sure that the controls that you were adding to the stream in CreateChildControls are added to the output control collection.

  1. protected override void Render(HtmlTextWriter writer)
  2. {
  3. EnsureChildControls();
  4. RenderChildren(writer);
  5. }

That’s it! Your first CardSpace WebPart. Albeit, a really simple one. At least you got to experience a little bit of CardSpace programming.

For deployment purposes, if you really wanted to do, you could then use a SharePoint feature file. This would involve the elementManifest.xml and feature.xml file.

Feature.xml File For CardSpace ClaimInterrogationWebPart

  1. <Feature  Title="ClaimInterrogationWebPart" Id="98c31c09-74ba-401d-ac9c-4906cd2b977b" Description="" Version="1.0.0.0" Scope="Site" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">
  2. <ElementManifests>
  3. <ElementManifest Location="elementManifest.xml" />
  4. <ElementFile Location="ClaimInterrogation.webpart" />
  5. </ElementManifests>
  6. </Feature>

elementManifest.xml File For CardSpace ClaimInterrogationWebPart

  1. <Elements  xmlns="http://schemas.microsoft.com/sharepoint/">
  2. <Module Name="WebParts" List="113" Url="_catalogs/wp" >
  3. <File Url="ClaimInterrogation.webpart" Type="GhostableInLibrary" />
  4. </Module>
  5. </Elements>

In later posts, where I introduce the CardSpace controls, we will dip into a little more hardcore CardSpace programming, as this was only a brief introduction for WebPart developers :-)

share save 171 16 Your First InfoCard WebPart (CardSpace WebPart Example)

No Comments

Trackbacks/Pingbacks

  1. Websites tagged "infocard" on Postsaver - [...] 2009-04-19 - A Video Sharing Website based on Web 2.0 Patterns saved by soumayuki2009-04-18 - Your First InfoCard WebPart …

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>