Sample Code for calculating the number of visitors on a static html page

Source: Internet
Author: User

This document describes how to calculate the number of visitors on a static html page.

  1. Static Page staticHtml.html
  2. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "
  3. <Html xmlns = "
  4. <Head>
  5. <Title> several methods for collecting dynamic page access volume </title>
  6. </Head>
  7. <Body>
  8. This is displayed in the layer
  9. <Div id = "pv"> </div>
  10. <Script src = "act. aspx"> </script>
  11. </Body>
  12. </Html>
  13. Accumulate page act. aspx
  14. <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "act. aspx. cs" Inherits = "AddNumber" %>
  15. Act. aspx. cs
  16. Code
  17. Public partial class AddNumber: System. Web. UI. Page
  18. {
  19. Private static int count = 1;
  20. Protected void Page_Load (object sender, EventArgs e)
  21. {
  22. Count;
  23. Response. Write ("var pv = document. getElementById (pv); pv. innerText =" count ";");
  24. }
  25. }
  26. Static Page staticHtml.html
  27. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "
  28. <Html xmlns = "
  29. <Head>
  30. <Title> several methods for collecting dynamic page access volume </title>
  31. </Head>
  32. <Body>
  33. This is to use images for display.
  34. </Body>
  35. </Html>
  36. Accumulate page Imageact. aspx
  37. <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Imageact. aspx. cs" Inherits = "ImageAddNumber" %>
  38. Imageact. aspx. cs code
  39. Public partial class ImageAddNumber: System. Web. UI. Page
  40. {
  41. Private static int count = 1;
  42. Protected void Page_Load (object sender, EventArgs e)
  43. {
  44. Count;
  45. String pv = count. ToString ();
  46. System. Drawing. Bitmap image = new System. Drawing. Bitmap (int) Math. Ceiling (pv. Length * 12.5), 22 );
  47. Graphics g = Graphics. FromImage (image );
  48. // Background color
  49. G. Clear (Color. White );
  50. Font font = new System. Drawing. Font ("Arial", 12, (System. Drawing. FontStyle. Bold | System. Drawing. FontStyle. Italic ));
  51. System. drawing. drawing2D. linearGradientBrush brush = new System. drawing. drawing2D. linearGradientBrush (new Rectangle (0, 0, image. width, image. height), Color. white, Color. red, (float) 1.2f, true );
  52. G. DrawString (pv, font, brush, 0, 0 );
  53. G. DrawRectangle (new Pen (Color. Gold), 0, 0, image. Width-1, image. Height-1 );
  54. System. IO. MemoryStream MS = new System. IO. MemoryStream ();
  55. Image. Save (MS, System. Drawing. Imaging. ImageFormat. Gif );
  56. Response. ClearContent ();
  57. Response. ContentType = "image/Gif ";
  58. Response. BinaryWrite (ms. ToArray ());
  59. }
  60. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.