11. asp built-in Object Server

Source: Internet
Author: User
Tags metabase
Through the first nine articles of theory and practice, I believe everyone has a systematic understanding of ASP. Even so far, we have learned only four built-in ASP objects, but I have been able to write some practical small programs. Today, the author will continue to explain to you the last ASP built-in object-server.

Before starting this course, I still want to answer some common questions raised by my friends. Recently, many people have asked me how to build an Active Server Page environment on the server. I think it may be because I have not made it clear in the previous articles. Therefore, it is necessary to elaborate on this question at the beginning of this article.

ASP applications are completely based on Microsoft Internet infomation Server (IIS for short). IIS is used in two versions of Windows NT Server and workstation respectively (iis4.0 also has Windows 98, the functions are almost identical. The difference is the installation process. Generally, we use the IIS version on the NT server. In the NT server environment, the work of publishing information and managing sites is generally done through IIS. Generally, iis2.0 is run in NT4.0, but it does not support ASP. ASP must be installed independently after IIS is installed. The installation file is an ASP Installation Package released by Microsoft. It may be more than 9 MB and can be downloaded on Microsoft's website. After ASP is added to iis2.0, it is automatically upgraded to version 3.0. 2.0 and 3.0 are no major changes to Web servers, but they simply increase the ability to run ASP. After the installation is complete, run the Internet Service Manager and you will see the following screen:

 

Three services are provided in iis3.0: www, Gopher, and FTP. The WWW Service submits web pages for the client browser and allows the client to access the. asp file. Of course, you can install the latest version iis4.0 directly. The author also recommends that you install this version because it has higher web management functions and security. In iis4.0, the IIS management interface has undergone a fundamental change. The familiar Internet Service Manager is replaced by Microsoft Management Console (MMC. The interface is as follows:

How can I install iis4.0? When iis4.0 is installed on NT4.0, you must have installed nt SP3 and Internet assumer4.01 in your system. Note that the version of Internet Explorer must be 4.01 and the version is 4.72.3110.8. This is important, otherwise you will not be able to install iis4.0. The author spent one night upgrading the IE version on Microsoft's site to install the version.

IIS supports virtual directories. You can manage virtual directories by clicking the "directory" tab in the "server properties" dialog box. Creating a virtual directory is of great significance for managing web sites. First, the virtual directory hides important information about the site directory structure. In the browser, you can easily obtain the file path information of the page by selecting "View Source Code". If the physical path is used on the web page, this exposes important information about the site directory, which can easily lead to system attacks. Second, as long as the two machines have the same virtual directory, you can move the web page from one machine to another without making any changes to the page code. In addition, when you place a web page under a virtual directory, you can set different attributes for the directory, such as read, excute, and script. Read access means to pass the directory content from IIS to the browser. Execute access to execute executable files in this directory. When you need to use ASP, you must set the directory where you store the. asp file to "excute (execution )". The author suggests that you separate HTML files from ASP files and place them in different directories when setting the web site, and set the HTML subdirectory to "read ", setting the ASP sub-directory as "execution" not only facilitates web management, but also improves ASP program security and prevents program content from being accessed by customers. Because at the end of July this year, some network experts found a terrible bug in IIS, that is, when you are on a site. after adding: $ data to the ASP file, the client will be able to see this in the browser. all the source code of the ASP file is terrible for a site. Of course, Microsoft has already compiled a patch for this bug, but in order to completely eliminate this possibility, the author also suggests that you do not set the directory where. asp is located as readable.
Now that you have fully understood ASP server settings, let's go to the question: Learn about ASP's last built-in Object Server.

The server object provides access to methods and attributes on the server. Most of the methods and attributes serve as the functional services of the utility. With the server object, you can start ActiveX Object routines on the server and use the Active Server Service to provide functions such as HTML and URL encoding.

I. Syntax

Server. Property | Method

Ii. Attributes

The time-out value of scripttimeout, Which is timeout after the script runs beyond this time. The following code specifies that the server processing script times out after 100 seconds.

<% Server. scripttimeout = 100%>

Note that you can set the default scripttimeout value for the Web service or Web server by using the aspscripttimeout attribute in the metadatabase. The scripttimeout attribute cannot be set to smaller than the value specified in the metabase. For example, if numseconds is set to 60 and metabase is set to 90 seconds, the script times out after 90 seconds.
Iii. Methods

1. htmlencode Method

The htmlencode method allows you to encode a specific string in HTML. Although HTML can display most of the text you write into an ASP file, when you need to actually contain the characters used in the HTML tag, you will encounter problems. This is because when the browser reads such a string, it tries to explain it. For example, the following text:
This is a test of the htmlencode method. <Br> there should be no other line here.

Will be displayed in the browser:

This is a test of the htmlencode method.
There should be no other line here.

To avoid this problem, we need to use the htmlencode method of the server object and use the HTML character code that cannot be interpreted by the browser to replace the HTML Tag characters. Therefore, use the following code to display the correct htmlencode string and output the text as needed in the browser.
<%
Response. Write server. htmlencode ("this is a test of the htmlencode method. <Br> there should be no other line here. ") %>

2. urlencode Method

Just as the htmlencode method enables the customer to translate strings into acceptable HTML formats, the urlencode method of the server object can correctly encode strings according to URL rules, when string data is transmitted to the server as a URL, spaces or special characters are not allowed in the string. To do this, if you want to perform URL encoding before sending a string, you can use the server. urlencode method.
3. mappath Method

The mappath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Syntax: Server. mappath (PATH)

Path specifies the relative or virtual path to map to the physical directory. If the path starts with a forward slash (/) or backslash (/), the mappath method regards the path as a complete virtual path when returning the path. If the path does not start with a slash, The mappath method returns the path relative to the existing path in the. asp file. Note that the mappath method does not check whether the returned path is correct or whether it exists on the server.

For the following example, the data.txt file and the test. asp file containing the following scripts are all in the directory c:/inetpub/wwwroot/asp. C:/inetpub/wwwroot directory is set as the host directory of the server. The following example uses the server variable path_info to map the physical path of the current file. The following scripts
<% = Server. mappath (request. servervariables ("path_info") %>

Output

C:/inetpub/wwwroot/asp/test. asp

Because the path parameters in the following example do not start with a slash character, they are mapped to the current directory, where C:/inetpub/wwwroot/asp. The following scripts
<% = Server. mappath ("data.txt") %>
<% = Server. mappath ("ASP/data.txt") %>

Output
C:/inetpub/wwwroot/asp/data.txt
C:/inetpub/wwwroot/asp/data.txt

4. Createobject Method

Server. Createobject is probably the most practical and powerful feature in ASP. It is used to create ActiveX component instances registered on the server. This is a very important feature, because the use of ActiveX Components allows you to easily expand ActiveX capabilities, it is the use of ActiveX components, You can implement the vital functions, for example, database connections, file access, AD display, and other vbscripts cannot provide or simply rely on the functions that ActiveX alone can do. It is precisely because of these components that ASP has a powerful vitality.
The syntax is as follows:

Server. Createobject ("component name ")

By default, the object created by the server. Createobject method has a page scope. This means that after the current ASP page is processed, the server will automatically destroy these objects. To create an object with a session or application scope, you can use <Object> to mark and set the scope attribute of the session or application, or store the object in the dialog and Application variables. Example:
<% Set session ("ad") = server. Createobject ("mswc. adrotator") %>

Note that you cannot create an object instance with the same name as the built-in object. Otherwise, the following script will return an error.

<% Set response = server. Createobject ("response") %>

So far, we have learned all the built-in ASP objects. Are you very excited? In fact, ASP is very simple, as long as you continue to practice, I believe that after a period of time it is not difficult to become a master of ASP. Starting from the next article, the author will introduce ASP built-in ActiveX components, which is also a very important and practical part of ASP application. 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.