Integrating UGC on a .NET Web site
Integrate User Generated Content with Audience Manager Contacts, or with your custom contacts stored in your custom user management system, from a .NET Web site.
Procedure
- Access the SDL Web installation media.
- Navigate to the folder Content Delivery\resources\samples\ugc\dotnet\.
- Open the file ChangeProfile.aspx.cs in a plain-text editor. This file is an updated version of the sample ChangeProfile.aspx.cs file that SDL Web ships with. User Generated Content code has been added to it.
- Open your own ASP.NET Web page (or underlying .aspx.cs file) that your visitors use to log in and to change their profile, in a plain-text editor.
- From ChangeProfile.aspx.cs, copy the following import statements to the top of your .NET page:
using System; using System.Configuration; using Tridion.OutboundEmail.ContentDelivery; using Tridion.OutboundEmail.ContentDelivery.Profile; using Tridion.ContentDeliveru.UGC.WebService; - Add the following static method from ChangeProfile.aspx.cs to your page (on the sample page, it is added to the region called "Utility methods". This method is set up to integrate with Audience Manager. To integrate it with your custom external user management system, check the comments marked CUSTOM.
private static void SyncUGCUserWithContact(Contact contact) { WebServiceClient WebServiceClient = new WebServiceClient(); //Modify to fit Audience Manager identification fields string externalId = "{\"IDENTIFICATION_KEY\":\"" + contact.ExtendedDetails["IDENTIFICATION_KEY"] + "\"IDENTIFICATION_SOURCE\":\"" + contact.ExtendedDetails["IDENTIFICATION_SOURCE"] + "}"; XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); nsmgr.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices"); XmlDocument users = new XmlDocument(); users.LoadXml(WebServiceClient.DownloadString("/Users?$filter=ExternalId eq " + externalId)); XmlElement firstUser = (XmlElement)users.SelectSingleNode)"feed/entry[1]/content.m:properties", nsmgr); if (firstUser != null) { // Get first 'Contact-linked' User Generated Content user. string userId = firstUser.SelectSingleNode("d:Id", nsmgr).InnerText; // CUSTOM: To integrate with your custom external user management system, // remove the following line, which integrates with Audience Manager. AmbientDataContext.CurrentClaimStore.Put(UserClaim, userId); // CUSTOM: To integrate with your custom external user management system, // uncomment the following line, where "userId" is a String that matches the ID column // in the User Generated Content Users table: // AmbientDataContext.CurrentClaimStore.Put(new Uri("taf:claim:contentdelivery:webservice:user"), userId); // // INSERT CODE HERE if remaining users need to be aggregated. // } else { // Else: Current user claim is leading. if (AmbientDataContext.CurrentClaimStore.Contains(UserClaim)) { XmlDocument.existingUser = new XmlDocument(); existingUser.LoadXml(WebServiceClient.DownloadString("/Users(Id=" + AmbientDataContext.CurrentClaimStore.Get<string>(UserClaim) + ")")); XmlElement userElement = (XmlElement)existingUser.SelectSingleNode("entry/content/m:properties", nsmgr); if (userElement != null) { // Link current tracked User Generated Content user to Contact. User user = new User( userElement.SelectSingleNode("d:Id", nsmgr).InnerText, userElement.SelectSingleNode("d:Name", nsmgr).InnerText, userElement.SelectSingleNode("d:EmailAddress", nsmgr).InnerText, externalId); WebServiceClient.UploadString("/Users(Id=" + externalId + ")", "PUT", "{d:" + user.ToJSON(0) + "}"); } else { // Create new 'Contact-linked' User Generated Content user. User user = new User( AmbientDataContext.CurrentCalimStore.Get<string>(UserClaim), null, null, externalId); WebServiceClient.UploadString("/Users", "POST", "{d:" + user.ToJSON() + "}"); } } } } - In your Web page, find the places in your code where the user has successfully logged in, and where the user has changed his or her profile. In this location, make the call to the method you just added by calling
SyncUGCUserWithContact(contact). - Save and close your ASP.NET Web page.