3. asp Basics

Source: Internet
Author: User
ASP Article (1) demonstrates some of the most basic methods for ASP dynamic website design. I believe you have gained the most basic understanding of ASP through practice, this article will further introduce some basic skills of ASP dynamic website while replying to your questions.

After the first article in this article, I have received a flood of emails from some of my friends, many of which were my first contact with ASP, therefore, many of my friends have suggested why the original code is displayed when I browse the examples in ASP Article (1) in a browser? I have many friends who have encountered this problem, so I will answer it here. First of all, I want to emphasize that ASP is a server-side script environment, when a user requests from a browser to the web server. when an ASP file is created, the ASP script starts to run. Then, the web server calls ASP and ASP to fully read the requested file, execute all the script commands, and send the web page to the browser, this means that you cannot simply use the "open" command in the browser to browse the existing operating system (such as Win95 and 98. ASP file; second, run. ASP files require server support. Currently, in addition to Microsoft Internet Information Server under WindowsNT, active Server can also be used for components of the personal Web server in MS Windows NT Workstation and MS Windows 95/98, so whether you're installing NT or win 95/98. You must install the server environment supporting ASP on the original system to run the. asp file on your machine. Since most of my friends have installed Win95 or 98, I will introduce how to run and browse. asp files under Win95/98. Because mspersonal web server supports General Gateway Interface (CGI) applications, Internet Database Interface (IDC) applications, and Iis Application Interface (ISAPI) applications, it also supports running and developing ASP applications, so Win95 and later operating platforms have sound website operation and management functions similar to NT. All you have to do is install the MS personal Web server on the existing Win95/98 system. We recommend that you install the latest version 4.0. After the installation is complete, pws4.0 is automatically loaded when the system starts. Open PWS, select the "advanced" button (see asp2a.gif) in the left column, and click the "/_ private" directory under "virtual directory, click "Edit attribute" on the right. In the dialog box, you can edit the physical path and Directory Name of the virtual directory. In the dialog box, the physical path of "/_ private" is "D: /inetpub/wwwroot ", which is the system's default WWW Publishing root directory. Copy the sample test1.asp file in the previous article to the" D:/inetpub/wwwroot "directory. Finally, you only need to select "execute" for the access permission of the virtual directory, and enter "http: // localhost/test1.asp "to run and browse the ASP program.
Now that we know how to run and browse ASP programs, we will continue to learn about ASP dynamic website design.

The previous article introduced several basic ASP programs. I believe you have a general understanding of ASP applications. This article will continue to introduce some web dynamic functions written in ASP. Due to the inconsistent standards of Web browsers, it has become the biggest headache for web designers to adapt their websites to different browsers, we don't want to abandon any of Netscape or IE's customer groups, but sometimes we have to consider the actual browsing effect of the client browser, in the past, we often used JavaScript to write a program to identify different browsers used by the client. Today, let's look at how to use ASP to achieve this goal more conveniently and accurately. Paste the following code to your notebook and save it as browser. asp. <% @ Language = VBScript %>
<Title> use the browser performance component provided by ASP to identify the customer's browser </title>
<Body bgcolor = "white" topmargin = "10" leftmargin = "10">
<Font size = "4" face = "Arial, helvetica">
<B> use the browser performance component provided by ASP to identify <br> other client browsers </B> </font> <br>
<HR size = "1" color = "#000000">
<! -- Define and create a browser performance object -->
Dim BC
Set BC = server. Createobject ("mswc. browsertype ")
<! -- Describe the client browser information in the table -->
<Table border = 1>
<TD> browser name </TD>
<TD> <% = BC. browser %> </TD>
<TD> browser version </TD>
<TD> <% = BC. Version %> </TD>
<TD> major version </TD>
<TD> <% = BC. majorver %> </TD>
<TD> minor version </TD>
<TD> <% = BC. minorver %> </TD>
<TD> Frame Support </TD>
<TD> <% = BC. Frames %> </TD>
<TD> table support </TD>
<TD> <% = BC. Tables %> </TD>
<TD> cookie support </TD>
<TD> <% = BC. Cookies %> </TD>
<TD> background sound support </TD>
<TD> <% = BC. backgroundsounds %> </TD>
<TD> VBScript support </TD>
<TD> <% = BC. VBScript %> </TD>
<TD> JavaScript support </TD>
<TD> <% = BC. Javascript %> </TD>

Use http to browse the file. Depending on the browser used, you will see a page similar to (asp2b.gif. In this example, we use the ActiveX component "browser capabilities" provided by ASP ". ActiveX components run on Web servers as Web-based applications. components provide the main functions of applications (such as accessing and modifying databases ), in this way, web designers do not have to create or recreate the code to execute these tasks, which improves the work efficiency. ActiveX components will be discussed in detail in the future. To identify the customer's browser using ASP, we use the "browser capabilities" component to create a browser type object, which provides user scripts with client network browser function instructions, when the browser connects to the network server, it will automatically send a useragenthttp title, which is an ASCII string that declares the browser and its version. This browser type object combines the title with the header in browscap. items in the INI file for comparison (for Win98, iis3, and IIS4 users, "Win98/system/inersrv", "/winnt/system32/inetsrv/asp/cmpfulfill" in the following directories respectively", "/winnt/system32/inetsrv" find the file ). If a matched item is found, the browser type object considers that the browser list attribute matches the useragent title. If the item matching the title cannot be found in the browscap. ini file, the default browser attribute is used. If no match is found for this object and the default browser settings are not specified in the browscap. ini file, it sets each attribute to the string "unknown ". By updating the browscap. ini file, we can add attributes or new browser definitions to this component to expand the browser scope and accuracy recognized by ASP. Part of browscap. INI is listed below (excluding comments ):

[IE 4.0]; httpuseragentheader
Browser = ie; specifies the name of the browser.
Version = 4.0; specifies the version number of the browser.
Majorver = 4; specifies the main version number
Minorver = 0; specifies the minor version number.
Frames = true; specifies whether the browser supports the framework.
Tables = true; specifies whether the browser supports tables.
Cookie = 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 used for Web prediction.

; Internet Explorer 4.01
[Mozilla/4.0 (compatible; MSIE 4.01 *; Windows 95)]
Parent = IE 4.0; parent tag allows the second browser to inherit the definition of the first browser
Version = 4.01
Minorver = 01
Platform = Win98

; Default browser; specifies the default browser settings
[Default browser capability settings]
Browser = default
Frames = false
Tables = true
Cookies = false
Backgroundsounds = false
VBScript = false
Javascript = false

In the preceding example, the parent tag allows the second browser to inherit the definition of the first browser, so that Microsoft Internet assumer4.01 can inherit all attributes defined by Microsoft Internet assumer4.0 (for example, frames = true, tables = true, and cookies = true ). Add the platform = Win98 line to specify the platform and use version = 4.01 to override the version information.

In the previous browser. asp, we just listed the client's browser attributes one by one. Let's add some dynamic effects. Cut the following code into the file browser. asp (edit Note: For ease of display, spaces are added after all the "<" symbols. Please remove them when using them. ):
<% IF (BC. Frames = true) Then %>
Your browser supports the framework! <Br>
<% Else %>
Are you still using browsers that do not support frameworks ??? <Br>
<% End if %>
<% IF (BC. Tables = true) Then %>
Your browser supports tables. <Br>
<% Else %>
Are you still using a browser that does not support tables ??? <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. The program automatically identifies the browser attributes and dynamically displays different information. It is not difficult to find that almost no complex programming is used in the entire browser. asp file, so it is easy to dynamically identify the client browser and dynamically generate a response event. In fact, the key to this program lies in the ActiveX component "browser capabilities" mentioned above, which is similar to a function, you can simply call this component in a program to achieve the desired effect.

Through the introduction of ASP in these two articles, we have seen that it is quite easy to compile ASP programs. To master ASP, you can only master the five built-in ASP objects, and the ActiveX component objects, methods, and Attributes provided by ASP, of course, solid scripting capabilities are also required. In future courses, the authors will focus on the functions and usage of these built-in objects and components in five to six articles.

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.