Other ASP-Common components

Source: Internet
Author: User
Tags date ini log connect split system log zip
Author: scholar



When you use ASP to write server-side applications, you must rely on ActiveX
Component to powerful Web
The functions of the application, such as: you need to connect the database, the database online operation and so on.


In the two article, the author introduced the AD Rotator, Database Access
And so on, let's take a look at some other ASP-common components today.


First, Browser capabilities
Component is well known, not all browsers support today's Internet
Aspects of technology. There are some features that some browsers support while others do not support, such as
: ActiveX controls, video streaming, dynamic HTML, Flash, and scripting. Using ASP's
Browser capabilities components, you can design a "smart" Web
Page to render content in a format that is appropriate for browser performance. Browser Capabilities
Component to create a BrowserType
Object that provides user script with a description of the features of the client Web browser. This component recognizes information such as the version of the client's browser, mainly because when a client browser sends a page request to the server, it automatically sends a
The User Agent HTTP header, which is a declaration of the browser and its version of the ASCII
String. The Browser Capabilities component maps the User Agent to the file Browscap.ini
The browser indicated in the, and through the BrowserType
object to identify the client browser. If the object is in the Browscap.ini
The item that matches the title cannot be found in the file, then the default browser properties are used. If the object does not find a match and
Browscap.ini
The default browser setting is not specified in the file, it sets each property to a string
"UNKNOWN". By default, the Browscap.ini file is stored in the
Windows\system\inersrv (if 95/98+pws4) or nt\system32\inersrv (if it is NT)
directory, you can edit the text file yourself to add your own properties or modify the file according to the latest published browser version of the update file. Please look at the following
Checkcookie () procedure, using Cookies for Browsercap objects
property to determine whether the client browser supports cookies and returns information:


<%

Sub Checkcookie ()

Set browsercap=server.createobject ("MSWC. BrowserType ")

If Browsercap.cookie=true Then

Response.Write "Your browser supports cookie!"

Else

Response.Write "Sorry, the browser you are using does not support cookie!"

End If

End Sub

%>





About Browser Capabilities
For more information on components, see Dynamic Web Design Skills--asp article (2).



Second, File Access
Components If your age is large enough, you must have seen the "dinosaur age" CGI.
Guest book, that is the earliest embryonic form of WEB Guestbook. At that time on the Internet-based web
It is also difficult to connect to a server backend database in an application, so historical information in a guest book is not stored in the backend database as it is today. So where exactly are these data kept? The answer is "text file",
Cgi
The program can write information received from the client into a text file that is stored on the server side, which can be
HTML file or TXT
, so that programmers can save customer information without connecting to the database, but writing this class
CGI programs are cumbersome, and the simplest samples of such programs are listed below:


#!/usr/local/bin/perl

# Perl Location One your server

print "content-type:text/plain\n\n";

if ($ENV {' Request_method '}eq "POST") {

Read (STDIN, $buffer, $ENV {' content_length '});

}elsif ($ENV {' Request_method '}eq ' get ') {

$buffer = $ENV {' query_stirng '};

}

@pairs =split (/&/, $buffer);

foreach $pair (@pairs) {

($name, $value) =split (/=/, $pair);

$value =~tr/+//;

$value =~s/% ([a-f a-f 0-9][a-f a-f 0-9])/pack ("C", Hex ($))/eg;

$FORM {$name}= $value;}

$file _name= "Guestbook.txt"; #File name

#具体内容

Open (FILE, ">> $file _name") | | Die "Open File Error";

Print FILE "Record time": $date \ n ";

Print FILE "name": $FORM {' name '} ';

Print FILE "unit": $FORM {' Company '}\n ';

Print FILE "Phone": $FORM {' Phone '}

Print FILE "Address": $FORM {'}\n ';

Print FILE "Zip": $FORM {' Zip '}

Print FILE "mail Address": $FORM {' email '}\n ';

Print FILE "return comment": $FORM {' content '}

Close (FILE)


You can feel that compared to ASP this kind of CGI
Programs are less readable and easy to operate. Then you must ask the ASP
Is it possible to write files directly on the server? The answer is certainly yes. But a wise friend might think, since
ASP and WEB
The connection of the database is so convenient, why do we need to write the customer information in the text file again?
Asp
This function is not to gild the lily? Indeed, for our common guest books,
BBS and other WEB
In the case of an application, it is not possible to use a text file to replace a database, whether it is efficient or easy to perform, but in some
Web
In the field of application writing text files is not only a standard but also a relatively convenient method of database. If you were to
NT more familiar with words, you must know NT
Has a very powerful security mechanism that can automatically save information about almost all server operations and connections in a suffix named
. log files, in fact, this technology can also be used in the WEB
, used to record some of the customer login information. The following procedure is the use of ASP
Read and write the characteristics of the text file, in a WEB BBS
Program to create a feature that automatically records each user's speech record.


<%

Set fs = CreateObject ("Scripting.FileSystemObject")

ForReading = 1

' Open the file in read-only mode. This file cannot be written to.

ForAppending = 8

' Open the file and write at the end of the file.

Tristateusedefault =-2

TristateTrue =-1

Tristatefalse = 0


'-----------write to System log start--------

Servermap=server. MapPath ("\bbs\log\")

' Mapping System physical Path

temp=servermap& "\" &year (date) &month (date) & "\"

' Gets the physical path and time of the system and takes this as the physical path of the log file

If not FS. FolderExists (temp) Then

Fs. CreateFolder (temp)

End If

' Detects if a folder exists or automatically creates

Dim Syslo



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.