Friday, February 11, 2011

Getting started with Windows Identity Foundation

Windows Identity Foundation is Microsoft's new technology for creating Claims-based applications.  Even though Claims could be created earlier using the methods available in System.IdentityModel, Windows Identity Foundation is supposed to make it easier to create applications quickly to support Claims-based scenarios.  Instead of the System.IdentityModel namespace, Windows Identity Foundation uses the Microsoft.IdentityModel namespace.

In order to get started with Windows Identity Foundation, you will first need to have either Visual Studio 2008 or Visual Studio 2010 installed.

After that, you can download the Windows Identity Foundation Runtime as well as the Windows Identity Foundation SDK from these locations:

Windows Identity Foundation Runtime: http://support.microsoft.com/kb/974405

Windows Identity Foundation SDK: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c148b2df-c7af-46bb-9162-2c9422208504&displaylang=en


 Unfortunately, since most Windows Identity Foundation code samples were originally created for Visual Studio 2008, I will be using Visual Studio 2008 throughout this post.  Perhaps in a later post, I will be able to provide details using Visual Studio 2010.

  1.  First of all, create a new ASP.Net Web Application
    1. File menu-->New Project
    2. Visual C#-->Web
    3. ASP.Net Web Application 
    4.  Make sure the .Net Framework 3.5 is selected as the Target Framework
    5. Specify a name and location for the new Web Application and click OK 
  2.  By default, once the new Web Application is created, Visual Studio will create it using the built-in Visual Studio Web Server.  Unfortunately, because of the configuration of dynamic ports, this will cause problems later in the usage of the Web Application in conjunction with Windows Identity Foundation.  Therefore, we will have to change the settings of the Visual Studio Web Application.
    1. Right click on the Visual Studio project and select Properties
    2. Select Web in the left hand navigation
    3. Select the radio button for Specific Port
    4. Enter a port number of your choosing
    5. Enter a Virtual Path of your choosing or leave it at the default virtual path (/).  NOTE: You should be aware of this setting as this will affect the Application URI you enter in the Federation Utility wizard.
    6. Click on the Save button to save your project changes
  3.  Right click on the ASP.Net Web Application and select "Add STS Reference"
  4. This will open the Federation Utility Wizard 
    1. The Wizard will automatically populate the Application Configuration location with the current Web Application's web.config file path  
    2. For the Application URI, enter the Url that you entered earlier into the Web Settings for the ASP.Net Web Application project (ex: http://localhost/WIFWebAppSample)
    3. If you receive a prompt regarding not being hosted on a secure https connection, click Yes. 
    4.  
    5. The next screen will now ask about creating an STS.  Since you do not already have an STS available, select the option for "Create a new STS project in the current solution"
    6. You will now see a Summary screen displaying the various changes that will be made to support the STS.   
    7. Click the Finish button 
  5. The Visual Studio solution will now also include an ASP.Net Web Site project appended with an STS suffix (such as WIFWebAppSample_STS)
  6. As was the problem with the original ASP.Net Web Application, Visual Studio by default will use the built-in Visual Studio Web Server and therefore attempt to use dynamic ports.  This will cause issues with the reliable use of the ASP.Net Web Application in conjunction with the STS.
  7. Select the STS project in Visual Studio
    1. View the Properties for the Visual Studio STS Web Site project
    2. Change the selection for Use dynamic ports to false.
    3. Save the changes
  8. Now, right click on the Default.aspx page for the original ASP.Net Web Application (WIFWebAppSample) and View in Browser
  9. You should now be redirected to the Login.aspx page found in the ASP.Net Web Site STS (WIFWebAppSample_STS)
  10. Click on the Submit button and you should be redirected back to your original ASP.Net Web Application Default.aspx page.
  11. Congratulations, you have just completed your preliminary setup using Windows Identity Foundation!



No comments:

Post a Comment