Lesson Three: ASP Basics

Source: Internet
Author: User
Tags definition continue ini client root directory
This article ASP article

(1) Show the ASP Dynamic Web site design Some of the most basic methods, I believe that through the practice of the ASP has the most basic understanding, this article in reply to all the questions raised, will further introduce the ASP Dynamic Web site Some of the basic skills.

   Since the first published in this article, a stream of incoming letters from some friends, to the author's surprise, a considerable part of the initial contact with the ASP, so many friends have proposed why in the browser in the ASP article (1) to see the example of the original code? As there are more friends with this problem, the author answers this question together. First, I want to emphasize once again that ASP is a server-side scripting environment that when a user requests an. asp file from a browser to a WEB server, the ASP script starts running, and then the Web server invokes ASP, the ASP reads the requested file, executes all script commands, and routes the Web page to the browse , which means that you cannot simply browse by using the "open" command in the browser under the existing operating system (such as WIN95, 98), and secondly, the server-side support is required to run the. asp file, currently in addition to the Microsoft Int under WindowsNT Ernet Information Server supports Active Server technology, Active server can also be used in MS Windows NT Workstation and MS Windows 95/98 Personal Web server artifacts, so whether you install NT or WIN95/98, you must install an ASP-enabled server-side environment on the original system to enable your machine to run. asp files. Since most of our friends are currently installing WIN95 or 98, the author is here to highlight how to run and browse. asp files under WIN95/98. Because mspersonal Web Server supports Common Gateway Interface (CGI) applications, Internet Database Interface (IDC) applications, and IIS application Interface (ISAPI) applications, and enables the running and development of ASP applications, the W In95 and its future operation platform has a robust web site operation and management function similar to NT. All you have to do is install the MS Personal Web Server on the existing WIN95/98 system and recommend that you install the latest version 4.0. When the installation is complete, PWS4.0 will load automatically when the system starts. Open PWS, select the Advanced button in the left column (see figure Asp2a.gif below), click the "/_private" directory under virtual directory, and click the Edit Properties button on the right, as shown in the dialogIn the box you can edit the physical path and directory name of the virtual directory, the physical path to "/_private" in the figure above is "D:\Inetpub\wwwroot", which is the system default WWW publishing root directory, and copies the example test1.asp file from the previous article to the "D:\ Inetpub\Wwwroot "directory. Finally, you can run and browse the ASP program by simply selecting the access rights for the virtual directory as "execute" and entering "http://localhost/test1.asp" in the browser's address field.

Know how to run and browse the ASP program, the following we continue to the ASP Dynamic Web Design learning.

The last one to introduce a few of the most basic ASP procedures, I believe that we have a general understanding of the application of ASP, this article will continue to introduce a number of ASP-written web dynamic features. Because of the inconsistent web browser standards so that how to make their own web site to adapt to a variety of different browsers to become the most headaches of web designers, in today's situation, we will not be able to abandon Netscape or any of the customer base IE, But sometimes we have to consider the actual browsing effect of the client browser, in the past we used to write a program of JavaScript to identify the different browsers used by clients, so today let's look at how to use the ASP more convenient and accurate to achieve this goal. Clip the following code into your notebook and save it as browser.asp.

<%@ LANGUAGE = VBScript%>
< html>
< head>
< title> The browser performance components provided by ASP to identify the client browser </title>
< body bgcolor= "white" topmargin= "ten" leftmargin= "ten" >
< font size= "4" face= "Arial, Helvetica" >
< b> The browser performance components provided by ASP to differentiate < br> customer Browser </b></font>< br>
< hr size= "1" color= "#000000" >
<!--define and create browser performance objects-->
<%
Dim BC
Set BC = Server.CreateObject ("MSWC.") BrowserType ")
%>
<!--describe the customer's browser information in the table-->
< Table border=1>
< tr>
< Td>browser name</TD>
< td> <%=BC. Browser%> </td>
< tr>
< Td>browser version</TD>
< td> <%=BC. Version%> </td>
< tr>
< Td>major version</TD>
< td> <%=BC. Majorver%> </td>
< tr>
< Td>minor version</TD>
< td> <%=BC. Minorver%> </td>
< tr>
< Td>frame support</TD>
< td> <%=BC. Frames%> </td>
< tr>
< td>table support</TD>
< td> <%=BC. Tables%> </td>
< tr>
< Td>cookie support</TD>
< td> <%=BC. Cookies%> </td>
< tr>
< Td>background Sound support</td>
< td> <%=BC. Backgroundsounds%> </td>
< tr>
< Td>vbscript support</TD>
< td> <%=BC. VBScript%> </td>
< tr>
< Td>javascript support</TD>
< td> <%=BC. JavaScript%> </td>
</table>
</body>

Browsing the file in HTTP, depending on the browser you are using, you will see a page similar to the one shown below (Asp2b.gif). In this example we used an ASP-supplied ActiveX component-"Browser capabilities". ActiveX components run on a Web server as part of a web-based application, and components provide the primary functionality of the application (such as access, modify databases, and so on) so that Web designers do not have to create or re-create the code to perform these tasks, thereby increasing the efficiency of the work, with the ActiveX Components will be discussed in detail in the future. In order to identify the client browser using ASP, we have created a Browser Type object using the "Browser capabilities" component, which provides user scripts with descriptions of the client Web browser features, and when the browser is connected to a network server, It automatically sends a useragenthttp title, which is an ASCII string that declares the browser and its version. This Browser Type object compares the title to the items in the Browscap.ini file (Win98, IIS3, IIS4 users can "Win98\system\inersrv", "\winnt\system3" in the following directory, respectively) 2\inetsrv\asp\cmpnts "," \winnt\system32\inetsrv "to find the file). If a matching entry is found, the Browser Type object will consider the browser list property to match the useragent header. If the object does not find an entry in the Browscap.ini file that matches the title, the default browser properties are used. If the object does not find a match and the default browser setting is not specified in the Browscap.ini file, it sets each property to the string "UNKNOWN". By updating the Browscap.ini file, we can add attributes or new browser definitions to the component to enlarge the browser scope and accuracy that the ASP recognizes. Some of the content in Browscap.ini (excluding the annotation section) is listed below:

[IE 4.0];; HTTPUserAgentHeader
Browser=ie;; Specifies the name of the browser.
version=4.0;; Specifies the version number of the browser.
majorver=4;; Specify the major version number
minorver=0;; Specify a secondary version number
Frames=true;; Specifies whether the browser supports frames.
Tables=true;; Specifies whether the browser supports tables.
Cookies=true;; Specifies whether the browser supports cookies.
Backgroundsounds=true;; Specifies whether the browser supports background music.
Vbscript=true;; Specifies whether the browser supports VBScript.
Javascript=true;; Specifies whether the browser supports JScript.
Javaapplets=true;; Specifies whether the browser supports Java programs.
Activexcontrols=true;; Specifies whether the browser supports ActiveX controls.
Win16=false;; Specifies whether the browser supports Win16
Beta=false;; Specifies whether the browser is a beta version.
Cdf=true;; Specifies whether the browser supports the Channel Definition Format for Web prediction.

;; IE 4.01
[Mozilla/4.0 (compatible; MSIE 4.01*; Windows 95)]
Parent=ie 4.0;; Parent tag allows a second browser to inherit the definition of the first browser
version=4.01
Minorver=01
Platform=win98

;;D Efault Browser;;

Means

Set the default browser settings
[Default Browser Capability Settings]
Browser=default
Frames=false
Tables=true
Cookies=false
Backgroundsounds=false
Vbscript=false
Javascript=false

In the example above, the parent tag allows a second browser to inherit the definition of the first browser so that the Microsoft Internet Explorer4.01 definition inherits all of the properties of the Microsoft Internet Explorer4.0 definition (for example, FRA Mes=true, Tables=true and Cookies=true). and by adding platform=win98 rows to specify the platform, rewrite the version information with version=4.01.

In the previous browser.asp we simply listed the client browser's attribute one by one, let's add some dynamic effects here. Clip the following code into the file browser.asp (Edit Note: For the convenience of display, all the "<" symbol after adding a space, the actual use, please pay attention to remove. ):
<% if (Bc.frames = TRUE) then%>
Your browser supports the framework!< br>
<% Else%>
Are you still using browsers that do not support frames??? < br>
<% End If%>
<% if (Bc.tables = TRUE) then%>
Your browser supports the form. < br>
<% Else%>
Are you still using browsers that do not support tables??? < br>
<% End If%>
<% if (BC. backgroundsounds = TRUE) then%>
Have you heard the wonderful music??? < br>
<% Else%>
Unfortunately, your browser does not support background music. < br>
<% End If%>
<% if (Bc.vbscript = TRUE) then%>
Your browser supports VBScript. < br>
<% Else%>
Your browser does not support VBScript. < br>
<% End If%>
<% if (Bc.javascript = TRUE) then%>
Your browser supports Javascript. < br>
<% Else%>
Javascript is not supported by your browser. < br>
<% End If%>

Refresh browser.asp in your browser, the program will automatically identify the browser's properties and dynamically display different information. It is not difficult to find that in the entire browser.asp file almost no complex programming, it is easy to dynamically identify the client browser and dynamic response to the effect of the event. In fact, the key to this program is the ActiveX component mentioned earlier-"Browser capabilities", which acts like a function, simply by invoking the component in the program to achieve the desired effect.

Through the introduction of the two ASP, we have seen the preparation of ASP program is quite easy, to master the ASP, nothing more than the master ASP built-in five objects, as well as ASP provided by the ActiveX component objects, methods and attributes, of course, a solid script language writing ability is also necessary. In future courses, the authors will focus on the roles and usage of these built-in objects and components in five to six pages, so stay tuned.



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.