This article ASP (1) shows some of the most basic methods of ASP dynamic website design. I believe that through practice, you have already gained the most basic understanding of ASP. While answering the questions raised by everyone, this article will further introduce the ASP dynamic website. some basic tips.
Since the first article of this article was published, I have received letters from some friends, which unexpectedly exceeded the author's expectations. A considerable number of them were first contact with ASP, so many friends have asked why they browse ASP in their browsers (1) What I saw when I was in the example was the original code? Since there are many friends who encounter this problem, the author will answer it together. First of all, I want to emphasize again that ASP is a server-side scripting environment. When a user requests .asp files from the browser to the web server, the ASP script starts running, and then the web server calls ASP, and ASP fully reads the requested file and executes all Script commands and send web pages to the browser, which means you cannot simply use the Open command in the browser to browse the .asp file under the existing operating system (such as Win95, 98); secondly, run .asp files require server-side support. Currently, in addition to Microsoft Internet Information Server under Windows NT supporting Active Server technology, Active Server can also be used for components of Personal Web Server in MS Windows NT Workstation and MS Windows 95/98, so no matter you install it. Whether it is NT or WIN95/98, you must install ASP-enabled server-side environment on the original system to enable your machine to run the .asp file. Since most of your friends are currently installing Win95 or 98, the author will focus on how to run and browse .asp files under Win95/98. Because MSPersonal Web Server supports general-purpose gateway interface (CGI) applications, Internet database interface (IDC) applications, and IIS application program interface (ISAPI) applications, and supports the operation and development of ASP applications, Win95 and its later operating platforms It has sound website operation and management functions similar to NT. All you have to do is install MS Personal Web Server on your existing Win95/98 system, and it is recommended to install the latest version 4.0. When the installation is complete, PWS4.0 will automatically load when the system starts. Open PWS, select the advanced button in the left column (see Asp2a.gif in the figure below), click the /_private directory under the virtual directory, and then click the Edit Properties button on the right, as shown in the figure, you can edit this in the dialog box The physical path and directory name of the virtual directory. In the above figure, the physical path of /_private is D:/Inetpub/wwwroot. This directory is the system's default WWW publishing root directory. Copy the example test1.asp file in the previous article to D :/Inetpub/wwwroot directory. Finally, you can run and browse the ASP program by simply selecting the access permissions of the virtual directory as Execute and entering http://localhost/test1.asp in the browser's address bar.
After knowing how to run and browse ASP programs, let’s continue to learn about ASP dynamic website design.
The previous article introduces several basic ASP programs to you. I believe you have a general understanding of the application of ASP. This article will continue to introduce some WEB dynamic functions written in ASP. Due to the inconsistency of WEB browser standards, how to adapt the website you make to various browsers has become the most troublesome thing for website designers. Under the current situation, we are unwilling and cannot abandon it. Netscape or IE any customer group, but sometimes we have to consider the actual browsing effect of client browsers. In the past, we often used javascript to write a program to distinguish the different browsers used by clients. So today Let's see how to achieve this with more convenient and precise use of ASP. Cut the following code into your Notebook and save it as browser.asp. < %@ LANGUAGE = VBScript %>
<HTML>
< HEAD>
<TITLE>Use the browser performance components provided by ASP to identify client browsers< /TITLE>
< /HEAD>
< BODY BGCOLOR=White topmargin=10 leftmargin=10>
< font size=4 face=Arial, Helvetica
>
< b>Use the browser performance components provided by ASP to identify the client 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 information about the client browser in the form->
<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>
< /HTML>
Use http to browse the file. Depending on the browser you are using, you will see a page similar to the image below (Asp2b.gif). In this example, we used an ActiveX component provided by ASP--Browser Capabilities. ActiveX components run on a web server as part of a web-based application. The components provide the main functions of the application (such as accessing, modifying databases, etc.), so that WEB designers do not have to create or recreate code that performs these tasks, so that Improved work efficiency and will be discussed in detail in the future. To identify client browsers using ASP, here we use the Browser Capabilities component to create a Browser Type object that provides user scripts with client web browser functionality descriptions, which will be used when the browser connects to a web server. Automatically send a UserAgentHTTP header, which is an ASCII string declaring the browser and its version. This Browser Type object compares the title with the items in the Browscap.ini file (Win98, IIS3, and IIS4 users can win98/system/inersrv, /winnt/system32/inetsrv/asp/cmpnts, / winnt/system32/inetsrv Found the file). If a matching item is found, the Browser Type object will consider that the browser list attribute matches the UserAgent title. If the object cannot find an item that matches the title in the browser.ini file, the default browser properties will be used. If the object has neither a match found and the default browser settings are specified in the browser.ini file, it sets each property to the string UNKNOWN. We can add properties or new browser definitions to this component by updating the browser.ini file, thereby expanding the browser scope and accuracy recognized by ASP. The following lists some of the contents in browser.ini (excluding the comments section):
[IE 4.0] ;;HTTPUserAgentHeader
browser=IE ;;Specify the name of the browser.
Version=4.0 ;;Specify the version number of this browser.
major=4 ;;Specify the main version number
minorver=0 ;;Specify the secondary version number
frames=TRUE ;;Specify whether the browser supports frames.
tables=TRUE ;;Specify whether the browser supports tables.
cookies=TRUE ;;Specify whether the browser supports cookies.
backgroundsounds=TRUE ;;Specify 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;; Specify whether the browser supports Win16
beta=False ;;Specifies whether the browser is beta version.
cdf=True ;;Specifies whether the browser supports Channel Definition Format for Web Prediction.
;;ie 4.01
[Mozilla/4.0 (compatible; MSIE 4.01*; Windows 95)]
parent=IE 4.0;;The parent tag allows the second browser to inherit the definition of the first browser
version=4.01
minorver=01
platform=Win98
;;Default Browser ;;Specify the default browser settings
[Default Browser Capability Settings]
browser=Default
frames=FALSE
tables=TRUE
Cookies=FALSE
backgroundsounds=FALSE
vbscript=FALSE
javascript=FALSE
In the above example, the parent tag allows the second browser to inherit the definition of the first browser so that the Microsoft Internet Explorer4.01 definition can inherit the Microsoft Internet Explorer4.0 definition of all properties (for example, frames=TRUE, tables= TRUE and cookies=TRUE) . And specify the platform by adding the platform=Win98 line, and rewrite the version information with version=4.01.
In the previous browser.asp we just listed the properties of the client browser one by one. Let's add some dynamic effects below. Clip the following code into the file browser.asp ( Editor's note : For the convenience of display, all < symbols have been added with extra spaces. Please be careful to remove them when using them.):
< % if (bc.frames = TRUE) then %&g
t;
Your browser supports framework!< br>
< % else %>
Are you still using a browser that does not support frameworks???< br>
< % end if %>
< % if (bc.tables = TRUE) then %>
Your browser supports forms. < br>
< % else %>
Are you still using a browser that does not support forms???< br>
< % end if %>
< % if (bc.BackgroundSounds = TRUE) then %>
Have you heard 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 %>
Your browser does not support javascript. < br>
< % end if %>
Refresh browser.asp in your browser, and the program will automatically identify the browser's properties and dynamically display different information. It is not difficult to find that almost no complex programming is used in the entire browser.asp file, and it is easy to dynamically identify the client browser and dynamically generate response events. In fact, the key to this program lies in the Browser Capabilities mentioned above, which is similar to a Function, and you can achieve the effect you want by simply calling the component in the program.
Through these two introductions to ASP, you have already seen that writing ASP programs is quite easy. To master ASP, it is nothing more than mastering the five built-in objects of ASP, as well as the objects, methods and properties of ActiveX components provided by ASP. Of course, it is solid. The scripting language writing ability is also necessary. In future courses, the author will spend five to six chapters focusing on the functions and usage of these built-in objects and components, so please pay attention.