This article is a step-by-step procedure of creating Windows Azure Web Role ASP.NET application protected using Windows Azure AppFabric Access Control Service v.2.0. After completing this walkthrough you will have a web application running in Windows Azure production environment that requires authentication using Windows Live ID or Google account. Live demo is available here https://wawithacsv2.cloudapp.net/ As a prerequisite of completing this walkthrough you should have an active Windows Azure account (sign up here, fees apply) and active Windows Azure AppFabric labs account (sign up free here)
Content in this step adopted and adapted from Code Quick Launch: Create and deploy an ASP.NET application in Windows Azure.
Launch Microsoft Visual Studio 2010 with administrator privileges. To launch Visual Studio with administrator privileges, right-click Microsoft Visual Studio 2010 and then click Run as administrator.
On the File menu, click New, and then click Project.
Within the New Project dialog, navigate to Installed Templates, Visual C#, and click Cloud.
Click Windows Azure Project. If needed, modify the Location: field, which indicates where your solution will be stored. Click OK to close the New Project dialog.
Within the New Windows Azure Project dialog, navigate to Visual C#, click the ASP.NET Web Role, and then click the > symbol. This will add a web role to your Windows Azure solution. A web role provides an environment for running web sites or applications as supported by Internet Information Services (IIS) 7.0. Click OK to close the New Windows Azure Project dialog.
[Optional] At this point you could compile and run the application. However, you could also customize the text displayed in the web page by modifying Default.aspx. This won’t fundamentally change the application, but it will show you how similar this application is to a traditional (non-cloud) ASP.NET application. To modify Default.aspx, open Solution Explorer. If Solution Explorer is not visible, from the View menu click Solution Explorer. Within Solution Explorer, expand WebRole1 and double-click Default.aspx. Modify the Welcome to ASP.NET! text to become Welcome to ASP.NET in Windows Azure!. Save and close Default.aspx.
Compile and run the service by clicking Debug from the menu and then clicking Start Without Debugging.
Assuming no compile errors or client machine errors, at this point you should have the service successfully running in the local development environment.
Content in this step adopted and adapted from How To: Create My First Claims Aware ASP.NET application Integrated with ACS v2
If you have not created Windows Azure AppFabric project follow the steps below. If you already created Windows Azure AppFabric Project you can skip to creating a namespace which is next.
To create a Windows Azure AppFabric project
If you have not created Windows Azure AppFabric namespace follow the steps below. If you already created Windows Azure AppFabric namespace you can skip to launching Access Control management portal which is next.
To create namespace within your Windows Azure AppFabric project
To launch the ACS v2.0 Management Portal
On the Project page, once the service namespace you created in Step 2 is active, click Access Control.
You are redirected to the page that displays your project ID, allows you to delete the Service Namespace, or launch the ACS v2.0 Management Portal.
To launch the ACS v2.0 Management Portal, click Manage Access Control.
This section describes how to add identity providers to use with your relying party application for authentication. Identity Provider is a service that lets end users authenticate themselves to your application. For more information about identity providers, see Identity Providers.
To add identity provider
On the ACS v2.0 Management Portal, click Identity Providers.
On Identity Providers page, click Add Identity Provider, and then click Add button next to Google, doing so your users will be able to authenticate to your Web Application using their Google credentials. You can optionally choose other Identity Providers such as Live ID, Facebook, Yahoo!
The Add Google Identity Provider page prompts you to enter a login link text (the default is Google) and an image URL. This URL points to a file of an image that can be used as the login link for this identity provider (in this case, Google). Editing these fields is optional. For this demo, do not edit them, and click Save.
On Identity Providers page, click Return to Access Control Service to go back to the ACS v2.0 management portal main page.
This section describes how to setup a Relying Party Application. In ACS v2.0, a Relying Party Application is a projection of your web application into the system. It defines the URLs for your application, token format preference, token timeout, token signing options, and token encryption options. For more information about relying party applications, see Relying Party Applications
To setup a relying party application
On Add Relying Party Application page, do the following:
Click Save.
On Relying Party Applications page, click Return to Access Control Service to go back to the ACS v2.0 management portal main page.
This section describes how to define rules that drive how claims are passed from identity providers to your relying party application. For more information about rules and rule groups, see Rules and rule groups.
To create rules
You can find all the information and code necessary to modify your relying party application to work with ACS v2.0 on the Application Integration page. You will use this information when configuring your cloud web application for federated authentication.
To view the Application Integration page
https://YOURNAMESPACE.accesscontrol.appfabriclabs.com/FederationMetadata/2007-06/FederationMetadata.xml
This section describes how to integrate ACS v2.0 with the Windows Azure Web Role ASP.NET cloud application that you created in step 1. The essence of the step is configuring trust between the ASP.NET application (Relying Party) and ACS v2.0.
To configure trust between the ASP.NET Relying Party Application and ACS v2.0
In Federation Utility wizard, do the following:
On Security Token Service page, select Use Existing STS, enter the WS-Federation Metadata URL published by ACS v2, and then click Next. This is the URL you copied last in the previous step, it should look similar to the following:"
Once you successfully finish running the Federation Utility wizard, it adds a reference to the Microsoft.IdentityModel.dll assembly and writes values to your Web.config file that configures the Windows Identity Foundation in your ASP.NET MVC 2 Web Application (TestApp).
<system.web> <authorization> <deny users="?" /> </authorization>
<!--set this value--> <httpRuntime requestValidationMode="2.0"/>
<system.web> <!--set this value--> <httpRuntime requestValidationMode="2.0"/> <authorization> <deny users="?" /> </authorization>
Content in this step is adapted from Exercise 1: Enabling Federated Authentication for ASP.NET applications in Windows Azure
This step helps you prepare your ASP.NET cloud web application to be deployed to Windows Azure with its prerequisites such as WIF assembly. WIF runtime is not installed as part of Windows Azure environment. It also helps creating and configuring server certificates to enable secure communications over SSL. Server certificate is also required for WIF related functions work properly on Windows Azure.
To prepare application’s dependencies to be deployed to Windows Azure
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Web; using Microsoft.IdentityModel.Web.Configuration;
void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e) { // // Use the <serviceCertificate> to protect the cookies that are // sent to the client. // List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[] { new DeflateCookieTransform(), new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate), new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate) }); SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly()); e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler); } void Application_Start(object sender, EventArgs e) { FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated; }
The following procedure will help you create self signed certificate and configure it for Compute Emulator and the application’s usage
To create and configure self signed certificate
This procedure will help you configure the certificate for usage in your Compute Emulator.
To configure certificate for Compute Emulator
This procedure will help you configure Windows Azure Role’s Endpoint to use the certificate for SSL/HTTPS communications.
To configure Windows Azure Role’s Endpoint for SSL/HTTPS
Next procedure will help you configure the certificate for usage by WIF related functionality.
To configure certificate for WIF functionality
<serviceCertificate> <certificateReference x509FindType="FindByThumbprint" findValue="YOURTHUMBPRINTFROMPREVSTEP" storeLocation="LocalMachine" storeName="My" /> </serviceCertificate>
This procedure helps you configure your ACS v2.0 configuration to proper values. Since the URL changed (HTTPS vs. HTTP and the port number) it needs also to be updated in the ACS v2.0 Management Portal
To update your relying party configuration on ACS v2.0 Management Portal
This procedure will help you configure permissions for the application to access your certificate. The application by default runs in application pool under Network Service account. You need to grant permissions to this account so that it can use the certificate.
To grant certificate access permissions to application pool account
This procedure tests your configuration and validates its readiness to be deployed to Windows Azure environment.
To test readiness for Windows Azure deployment
In this step you will deploy the application to the cloud using the Windows Azure management portal. First you’ll need to create a service and a service configuration file, called service package, and then upload it to Windows Azure environment using Windows Azure management portal.
For Configuration file, click the corresponding Browse Locally… button, navigate to the folder where your ServiceConfiguration.cscfg is, and select the file.
Click on Add Certificate button to add your certificate to be deployed, but first you need to export the certificate into file. To export the certificate into file follow these steps:
Open mmc console by first clicking on Windows button in task bar and typing mmc. You should see mmc.exe appears in search results. Click on it.
When mmc console appears click on File option and then on Add/Remove Snap-in… option.
In the Add or Remove Snap-ins dialog box choose Certificates from the available snap-ins list and click on Add> button.
Choose Computer Account option and click Finish button.
In the Select Computer wizard page select Local Computer (the computer this console is running on) and click Finish button. The click OK button.
Expand Console Root folder.
Expand Certificates(Local Computer) folder.
Expand Personal folder.
Click on Certificates folder to list available certificates.
Locate your certificate in the list.
Right click on the certificate and choose All Tasks and then Export… option.
Click Next on the welcome page of the wizard.
On the Export Private Key page choose Yes, export the private key option and click Next button.
On the Export File Format leave the default option which is Personal Information Exchange - PKCS #12 (.PFX) and click Next button.
On the Password page of the wizard specify password. You will need it when uploading the certificate to Windows Azure environment via management portal.
On the File to Export page of the wizard specify destination file and click Next button. Make a note where you are saving the file. Note, since the certificate being exported has private key extra care should be taken to not exposing it to the public. It’s best if you delete the file altogether after uploading it to Windows Azure environment.
Click Finish to complete the wizard. You should be presented with The export was successful message, click OK button to dismiss the message.
Switch back to Windows Azure management portal where you opened a dialog box to locate your certificate (.PFX) file and locate the certificate file you have just exported.
Specify the password for your certificate in the Certificate Password field.
Click OK. You will receive a warning after you click OK because there is only one instance of the web role defined for your application (this setting is contained in the ServiceConfiguration.cscfg file). For purposes of this walk-through, override the warning by clicking Yes, but realize that you likely will want more than one instance of a web role for a robust application.
You can monitor the status of the deployment in the Windows Azure management portal by navigating to the Hosted Services section. Because this was a deployment to a staging environment, the DNS will be of the form http://<guid>.cloudapp.net. You can see the DNS name if you click the deployment name in the Windows Azure management portal (you may need to expand the Hosted Service node to see the deployment name); the DNS name is in the right hand pane of the portal. Once your deployment has a status of Ready (as indicated by the Windows Azure management portal), you can enter the DNS name in your browser (or click it from the Windows Azure management portal) to see that your application is deployed to the cloud.
Although this walk-through was for a deployment to the staging environment, a deployment to production follows the same steps, except you pick the production environment instead of staging. A deployment to production results in a DNS name based on the URL of your choice, instead of a GUID as used for staging.
If this is your first exposure to the Windows Azure management portal, take some time to familiarize yourself with its functionality. For example, similar to the way you deployed your application, the portal provides functionality for stopping, starting, deleting, or upgrading a deployment.
Important
Assuming no issues were encountered, at this point you have deployed your Windows Azure application to the cloud. However, before proceeding, realize that a deployed application, even if it is not running, will continue to accrue billable time for your subscription. Therefore, it is extremely important that you delete unwanted deployments from your Windows Azure subscription. To delete the deployment, use the Windows Azure management portal to first stop your deployment, and then delete your deployment. These steps take place within the Hosted Services section of the Windows Azure management portal: Navigate to your deployment, select it, and then click the Stop icon. After it is stopped, delete it by clicking the Delete icon. If you do not delete the deployment, billable charges will continue to accrue for your deployment, even if it is stopped.
Publish to production clicking on you deployment node so that Swap VIP ribbon appears.
Click on Swap VIP ribbon and then OK button. The deployment to production should take couple of minutes.
In the next procedure you will update the the package and the ACSv2 to reflect on the address changes from staging environment to production.
Next procedure helps you to verify your application is functional when running in Windows Azure environment.
Richard Mueller edited Revision 10. Comment: Replaced RGB values with color names in HTML to restore colors
Richard Mueller edited Revision 9. Comment: Fixed zero characters in <a name> tags in HTML
Carsten Siemens edited Revision 8. Comment: fixed typos
Dinesh Haridas edited Revision 6. Comment: fixed url path
Ed Price - MSFT edited Revision 5. Comment: There was a phantom Amazon.com link in the space at the top (the link was in the HTML code still).
Alik Levin edited Revision 3. Comment: updated links to MSDN v. condeplex
Alik Levin edited Revision 2. Comment: Changed the URL to sample demo on Azure