Chapter 9 Implementation of Site Statistics
So far, Doking's BLOG is operational. But you can find that the left navigation is still empty. The following chapters mainly add function menus to the left navigation. This chapter mainly explains how to add relevant site statistics on the left navigation.
Open the template dkblog.dwt.aspx and add text design to the left navigation as shown in Figure 9-1.
Figure 9-1 Template dkblog.dwt.aspx left navigation text design
The implementation of online people statistics relies on the global.asax file. The global.asax file contains program code for handling application-level events, just like the Global.asa file in classic ASP. The <script> tag in Global.asax contains application-level event handlers. The first group of event handlers handles the start and stop events of the application. A start event is raised the first time any page is requested. The application termination event will be awakened when the application is closed.
Creating the global.asax file usually requires manual editing. Now you can quickly create the global.asax file in Visual Web Developer 2005.
(1) Download and install Visual Web Developer 2005.
Visual Web Developer 2005 download address:
http://go.microsoft.com/fwlink/?linkid=30092&clcid=0x409
Download and install. After running, the welcome interface is shown in Figure 9-2.
Figure 9-2 Visual Web Developer 2005 welcome interface
(2) After Visual Web Developer 2005 is running, select [File] → [New File], and in the pop-up [New File] dialog box, expand "Web" of "Categories" option, and select "Visual Basic", select "Global Application Class" in "Templates", as shown in Figure 9-3.
Figure 9-3 Create a new Global Application Class
(3) Click the "Open" button and create a new Glbal file as shown in Figure 9-4.
Figure 9-4 A newly created Glbal file
(4) Modify the Glbal file, as shown in Figure 9-5 after modification.
Figure 9-5 Modify the Glbal file
(5) Save the Glbal file to the root directory of D:dkkblog with the file name Glbal.asax.
(6) Return to Dreamweaver, open the template dkblog.dwt.aspx, switch to code view, find the code:
<td class="BTD">Online population statistics of this site: people</td>
and change it to:
<td class="BTD">Statistics of online people on this site: <%=Application("dk_uses")%> people</td>
(7) Save the template.
Reminder: The Glball.asax file is created here using Visual Web Developer 2005, just for the convenience of readers, and at the same time, it also allows readers to get in touch with Visual Web Developer 2005. This new software is very powerful. If you don't have Visual Web Developer 2005, you can just create a new blank notepad, write the code shown in Figure 9-5 above, and save it as a Glball.asax file.
Recall that in "7.1 User Login to Server Behavior", we once counted the notes and replies posted by users. The statistics of site notes and replies are similar to this.
(1) Open the template dkblog.dwt.aspx, create a new data set zdbj, and its settings are shown in Figure 9-6; create a new data set zdhf, and its settings are shown in Figure 9-7.
Figure 9-6 Setting diagram of data set zdbj
Figure 9-7 Setting diagram of data set zdhf
(2) Bind data set zbbj and data set zbhf to the page respectively, as shown in Figure 9-8.
Figure 9-8 Bind data sets zbbj and zbhf
(3) Save the template dkblog.dwt.aspx and update all web pages.