ASP counter Design detailed

Source: Internet
Author: User
The Active server Pager (Dynamic Servers home page, abbreviated as ASP) can easily implement page counter functionality by reading and writing server files, combining the script language (VBScript or JScript) and HTML code. Now popular ASP textbooks and ASP tutorials on the network have talked about the design of ASP counters, but are too simple, such as not mention how to implement counter script and the separation of the main page and the implementation of the image counter. The following is the author for the organization of the experience of the NT Web site, give an example step-by-step talk about the design of ASP counters, I hope to give the ASP's Beginners and ASP Web programming interested in some of the netizens some inspiration.
(a) Simple counter
ASP contains five built-in "Active Server Components" (ActiveX server components), which is database access component, file access component (Files Access component) , Ad Rotator Component (AD-carousel component), Brower capabilities component (Browser information component), Content Linking component (contents link component). The counter we want to design is to read and write the server file through the file access component. The algorithm idea is: In the server side with a text (ASCII) file to store the count value, whenever the page is accessed from the file read out the value, displayed to the user, and the value plus 1, the added value to write back to the file.
The ASP statements that write data to a server count file are described below:
Counfile=server.mappath ("FileName to hold counter value")
The server server access method MapPath (path) Converts the path of the file that holds the counter value to the physical path
SET fileobject=server.createobject ("Scripting.FileSystemObject")
' Use method createobject to define objects FileSystemObject
SET Outstream=server.createtextfile (Fileobject,true,false)
' Use object FileSystemObject provide method CreateTextFile generate text file, where parameter ' True ' means overwrite original file, ' False ' means file is ASCII type
Outstream.writeline "Data to write"
' Outstream.writeline writes a row of data to a file
The ASP syntax for reading data from a server file is as follows:
Counfile=server.mappath ("FileName to hold counter value")
SET fileobject=server.createobject ("Scripting.FileSystemObject")
SET Instream=server.opentextfile (Fileobject,1,false,false)
' Use object FileSystemObject to provide methods OpenTextFile generate text files,
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.