Requirements: Adrotator Control Allows Developers To Place Graphical Advertisements On A Web Form and
Requirements: Adrotator Control Allows Developers To Place Graphical Advertisements On A Web Form and
NET Web site and how to implement custom "click tracking" logic. Many e-commerce sites use banner advertisements to promote products and services on behalf of customers. The AdRotator control allows developers to place graphical advertisements on a Web Form and provides programmatic functionality that enables the development of custom logic to track advertisement clicks. Back to the top
Requirements
This article assumes that you are familiar with the following topics:
ASP.NET Web application development with Visual Basic .NET Extensible Markup Language (XML) syntax
2. On the File menu, click Add New Item, and then click XML File to add an .xml file named Adverts.xml. 3. Use the Visual Studio XML editor to edit Adverts.xml so that it reads as follows:
4. <?xml version="1.0" encoding="utf-8" ?> 5. <Advertisements> 6. <Ad> 7. <!-- The URL for the ad image --> 8. <ImageUrl>images/microsoft.bmp</ImageUrl> 9. <!-- The URL the ad redirects the user to --> 10. <NavigateUrl>http://www.microsoft.com</NavigateUrl> 11. <!-- The alternate text for the image --> 12. <AlternateText>Visit Microsoft's Site</AlternateText> 13. <!-- The relative number of times this ad should appear --> 14. <!-- compared to the others --> 15. <Impressions>80</Impressions> 16. <!-- The topic of this ad (used for filtering) --> 17. <Keyword>ProductInfo</Keyword> 18. </Ad> 19. <Ad> 20. <ImageUrl>images/technet.bmp</ImageUrl> 21. <NavigateUrl>http://www.microsoft.com/technet</NavigateUrl> 22. <AlternateText>Support for IT Professionals</AlternateText> 23. <Impressions>40</Impressions> 24. <Keyword>Support</Keyword> 25. </Ad> 26. <Ad> 27. <ImageUrl>images/msdn.bmp</ImageUrl> 28. <NavigateUrl>http://msdn.microsoft.com</NavigateUrl> 29. <AlternateText>Support for developers</AlternateText> 30. <Impressions>40</Impressions> 31. <Keyword>Support</Keyword> 32. </Ad> 33. </Advertisements>
NOTE: Remember that XML is case-sensitive. Ensure that your document exactly matches the preceding code. 34. Save Adverts.xml Back to the top
4. Click AdRotator1 (the newly added AdRotator control), and then press the F4 key to view its properties. 5. Set the AdvertisementFile property to Adverts.xml. 6. Save Default.aspx, and build the project. Back to the top
6. Save Default.aspx 7. Add a new Web Form named AdRedirect.aspx. 8. Add the following Visual Basic code to the Page_Load event procedure in AdRedirect.aspx:
9. Dim strAdPath As String 10. 11. 'Get the URL to navigate to. 12. strAdPath = Request.QueryString("Adpath") 13. 14. 'Log the ad click to a text file (you can use a database). 15. Dim AdFile As New IO.FileInfo(Server.MapPath("AdResponse.txt")) 16. Dim AdData As IO.StreamWriter 17. AdData = AdFile.AppendText 18. AdData.WriteLine(Now().ToString & ": Ad clicked. Redirect to " & _ 19. strAdPath)
20. AdData.Close() 21. 22. 'Redirect the user to the ad URL. 23. Response.Redirect(strAdPath)
24. Save AdRedirect.aspx, and build the project. Back to the top