11.ASP built-in object Server

xiaoxiao2021-03-06  41

Through the theory and practice of the top nine, I believe that everyone has had a systematic understanding of the ASP. Although so far, we only learn the four built-in objects of the ASP, but it is fully able to write some practical applets. Today, the author will continue to explain the last ASP built-in object - Server.

Before starting this course, I still have to answer some common problems present here. There are still many friends recently to ask me, how to build a server-side Active Server Page environment. I think it may be that I have not explained in the first few, so it is necessary to explain this problem in detail in the beginning of this article.

The ASP app is completely on Microsoft Internet Infomation Server (IIS), IIS has two versions of Windows NT Server and Workstation, respectively (of course IIS4.0 also have Windows 98 version, here is not mentioned), its function Almost identical, different is just the installation process. In general, we are using IIS version based on NT servers. In the NT Server environment, publish information, the management site is generally done by IIS. Usually we run in the NT4.0 version of the IIS2.0, but it does not have the ability to support the ASP. ASP must be installed separately after IIS, the installation file is a Microsoft released ASP installation package, about 9 trillings, you should download it on Microsoft's website. Once IIS2.0 adds a function of supporting the ASP, it will automatically upgrade to version 3.0. 2.0 and 3.0 For web servers, there is no big change, just simply adding the ability to run the ASP. When the installation is complete, run the Internet Service Manager, you will see the following screen:

You can provide three services in IIS3.0: WWW, Gopher, FTP, WWW services Submit the web page for the Customer Browser and allow customers to access the .asp file. Of course, you can install the latest IIS4.0 version directly, and the author also recommends that this version is installed because it has more higher Web management functions and security. In the IIS's management interface, the familiar Internet service manager is replaced by Microsoft Management Console, referred to as MMC. The interface is as follows:

So how do you install IIS4.0? When installing IIS4.0 on NT4.0, NT SP3, and Internet Explorer4.01 must already be installed. Note that the version of Internet Explorer here must be 4.01, version number is 4.72.3110.8. This is important, otherwise you will not be able to install IIS4.0. In order to install this version, the author upgraded the IE version on Microsoft's site.

IIS supports virtual directory, manage virtual directories by "Directory" tab in the Server Properties dialog. Establishing a virtual directory is very important for managing Web sites. First, the virtual directory hides important information about the site directory structure. Because the customer can obtain the file path information of the page by selecting "View Source Code", it is easy to obtain the file path information of the page. If you use the physical path in the web page, you will expose important information about the site directory, which is easy to cause the system to be attacked. . Second, as long as the two machines have the same virtual directory, you can move the web page from one machine from one machine without any changes to the page code. Also, when you place a web page in a virtual directory, you can set different properties to your directory, such as: Read, Excute, Script. Read Access Indicates that directory content is passed from IIS to your browser. The execution of access can perform executable files in this directory. When you need to use the ASP, you must set the directory of the .asp file to "Excute". Author I suggest that when you set up a web site, place the HTML file in different directories with the ASP file, and set the HTML subdirectory to "Read", set the ASP subdirectory to "Execute", which is not only convenient for Web Management, and most importantly improve the security of the ASP program to prevent program content from being accessed by the customer. Because IIS was discovered by some web masters at the end of July this year, it was, when you add: $ data after you add: $ DATA, the customer will be able to see the browser All source code for .asp files, this is very terrible for a site. Of course, Microsoft has written patches for this bug, but in order to completely eliminate the occurrence of this possibility, the author is also a suggestion not to set the .asp's directory to be readable. I think, now you should have fully understood the ASP server side settings. Let's go to the topic - learn the last built-in object server for ASP.

Server objects provide access to methods and properties on the server, most of which are serviced as a utility. With a Server object, you can launch an ActiveX object routine on the server and use the Active Server service to provide functions such as HTML and URL encoding.

First, grammar

Server.property | Method

Second, attribute

The ScriptTimeout timeout value is timeout processing after the script runs more than this time. The following code specifies that the server processing script is timeout after 100 seconds.

<% Server.scripttimeout = 100%>

It should be noted here that the default scripttimeout value can be set for the web service or web server by using the ASPScriptTimeout property in the metabase. The ScriptTimeOut property cannot be set to be smaller than the value specified in the metabase. For example, if Numseconds is set to 60, the metabase setting contains the default value for 90 seconds, the script is timeout after 90 seconds.

Third, method

1, HTMLENCODE method

The HTMLEncode method allows you to do HTML encoding for a specific string, although HTML can display most you write text in the ASP file, but you will encounter problems when you need to actually contain characters used in the HTML tag. This is because when the browser reads such a string, try to explain. For example, the following text:

This is a test for the HTMLENCODE method.
here should not come another line.

Will be displayed by the browser:

This is a test for the HTMLENCODE method. There should be no one by another line here.

To avoid such problems, we need to use the HTMLENCode method for the Server object, and use the corresponding HTML Character Code that is not interpreted by the browser. HTML tag character. So, use the following code to display the correct HTMLENCode string so that you need to output your text in your browser.

<%

Response.write Server.htmlencode ("This is a test for the HTMLENCode method.
should not be another line here.")%>

2, urLencode method

As htmlencode methods allow customers to translate strings into an acceptable HTML format, the URLENCode method of the Server object can correctly encode the string according to the URL rule, when the string data is passed to the server as the URL, in the character Spaces are not allowed in the string, nor allowing special characters. To do this, if you want to make 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.

The syntax is as follows: Server.mappath (PATH)

PATH Specifies the relative or virtual path to map the physical directory. If the PATH starts with a positive slash (/) or the backslash (/), the mappath method returns PATH as a complete virtual path when the mappath method returns the path. If the PATH is not started with a slash, the mappath method returns the path to the existing path in the .asp file. It should be noted here that the mappath method does not check if the return path is correct or it exists on the server.

For the following examples, file data.txt and TEST.ASP files containing the following scripts are located under the directory C: / INETPUB / WWWROOT / ASP. The C: / INETPUB / WWWROOT directory is set to the server's host directory. The following example uses server variable path_info to map the physical path to the current file. The following script

<% = server.mappath (Request.ServerVariables ("Path_INFO"))%>

Output

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

Since the path parameters in the following examples are not started with slash characters, they are relatively mapped to the current directory, here is the directory C: / INETPUB / WWWWROOT / ASP. The following script

<% = server.mappath ("data.txt")%>

<% = server.mAppath ("ASP / DATA.TXT")%>

Output

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

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

4, CreateObject method

Server.createObject is probably the most practical and strongest features in ASP. It is used to create an instance of ActiveX component already registered on the server. This is a very important feature, because you can easily extend ActiveX components, you can use ActiveX components, you can implement critical features, such as database connections, file access, advertising display, and other VBScript cannot provide or simply rely on features that ActiveX can complete separately. It is because these components have made ASP have a powerful vitality.

The syntax is as follows:

Server.createObject ("Component Name")

By default, the objects created by the Server.createObject method have a page scope. That is to say, after the current ASP page processing is complete, the server will automatically destroy these objects. If you want to create an object with a session or application scope, you can use the tag and set the SCope property of the session or Application, or store the object in a dialog and application variables. The following routine: <% SET session ("ad") = server.createObject ("mswc.adrotator")%>

It should be noted here that an object instance that is the same as the built-in object cannot be created, otherwise, an error will be returned if the following script will return.

<% SET Response = Server.createObject ("Response")%>

So far, we have already learned all the built-in objects of the ASP. I don't know if everyone is very excited. In fact, the ASP is very simple. As long as everyone is constantly practicing, I believe that it is not difficult to become ASP for a while. From the next article, the author will begin to introduce the ASP built-in ActiveX component, which is also a very important and practical part of the ASP application. stay tuned.

转载请注明原文地址:https://www.9cbs.com/read-58012.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.040, SQL: 9