Lesson 11th: ASP Built-in Object Server

Source: Internet
Author: User
Tags continue iis relative variable urlencode metabase
Through the first nine of the theory and practice, I believe that we have a systematic understanding of ASP, although so far, we have only learned the ASP's 4 built-in objects, but has been able to write a number of practical small programs. Today, the author will continue to explain to you the last ASP built-in object--server.

Before I begin this course, I will still be here to answer some of the more general questions raised by my friends. There are still a lot of letters from friends asking me how to build a server-side Active server Page environment. I think I have not made it clear in the previous few, so it is necessary to elaborate on this issue at the beginning of this article.

The ASP application is based entirely on Microsoft Internet infomation Server (IIS), and IIS has two versions for Windows NT server and WorkStation (of course IIS4.0 also has Windows98 version, this is not mentioned here, its function is almost identical, the difference is just the installation process. Generally speaking, we are using the IIS version on the NT server. In an NT Server environment, publishing information and managing sites are generally done through IIS. Normally we run the IIS2.0 version in the NT4.0 version, but it does not have the functionality to support ASP. The ASP must be installed separately after installing IIS, the installation file is a Microsoft Release ASP installation package, about 9 trillion, should be able to download on Microsoft's website. When the IIS2.0 feature is added to support ASP, it is automatically upgraded to version 3.0. 2.0 and 3.0 for the WEB server, there is no major changes, but simply increased the ability to run ASP. When the installation is complete, run Internet Services Manager, and you will see the following screen:

So how do I install I IS4.0? When installing I IS4.0 on n T4.0, you must have already installed n T SP3 on your system, and I nternet Explorer4.01, note that the version of I nternet Explorer here must be 4.01, the version number is 4.72.3110.8. This is important, otherwise you will not be able to install I IS4.0. In order to install this version, the author deliberately spent one night upgrading the I-E version at Microsoft's site.

IIS supports virtual directories, which can be managed by the Directory tab in the Server Properties dialog box. Establishing a virtual directory is very important for managing WEB sites. First, the virtual directory hides important information about the site directory structure. Because in the browser, the customer can easily get the file path information of the page by selecting "View Source code", and if the physical path is used on the WEB page, it will expose important information about the site directory, which could easily cause the system to be attacked. Second, as long as 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. Also, when you place a WEB page in a virtual directory, you can set different properties for the directory, such as Read, Excute, Script. Read access represents the delivery of directory content from IIS to the browser. and executing access enables executable files to be executed within that directory. When you need to use ASP, you must set the directory of your. asp files to "Excute". The author suggests that when you set up a Web site, placing HTML files in separate directories with ASP files, and then setting the HTML subdirectory to "read" and setting ASP subdirectories to "execute", not only facilitates the management of the WEB, but also the most important to improve the security of ASP programs and prevent The program content is accessed by the customer. Because at the end of July this year, IIS was found by some network masters a terrible bug, that is, when you are in a site of the. asp file after adding:: $DATA, customers will be able to see in the browser all the source code of the. asp file, which is very scary for a site. Of course, Microsoft has written a patch for this bug, but in order to completely eliminate this possibility, the author also suggested that you do not set the directory where the ASP is located to be readable.

I think that now you should have a full understanding of the ASP server-side settings, let's go to the business-learn the ASP's last built-in Object server.

The server object provides access to methods and properties on the server, where most of the methods and properties are serviced as functionality 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. Grammar Server.property|method

Second, the attribute ScriptTimeout timeout value, which is timed out after the script runs beyond that time. The following code specifies that the server processing script times out after 100 seconds.

<% server.scripttimeout=100%> Here you need to be aware that by using the A spscripttimeout attribute in the metabase you can set the default S Cripttim for the W EB Service or the W EB server Eout value. The S Cripttimeout property cannot be set to less than the value specified in the metabase. For example, if Numseconds is set to 6 0, and the metabase setting contains a default value of 9 0 seconds, the script times out after 9 0 seconds.

Iii. Method 1, HTMLEncode method

The H Tmlencode method allows you to encode H TML for a particular string, although H TML can display most of the text you write to the A SP file, but you will encounter problems when you need to actually include the characters used in the H TML tag. This is because when the browser reads such a string, it tries to interpret 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 by the browser as:

This is a test of the HTMLEncode method.
There should not be another line here.

In order to avoid such problems, we need to use the H-Tmlencode method of the S Erver object, and use the corresponding H-TML Character Code, which is not interpreted by the browser, to replace the H TML tag character. So, use the following code to display the correct H tmlencode string so that you can output text in your browser as you want.
<%
Response.Write Server.HTMLEncode ("This is a test of the HTMLEncode method.) < br> there should be no other line here. ")%>
2, the UrlEncode method is like the H Tmlencode method enables the customer to translate the string into an acceptable H TML format, the U-Rlencode method of the S Erver object can encode the string correctly according to the U-RL rule, when the string number When passed to the server as a U-RL, spaces are not allowed in strings and special characters are not allowed. To do this, if you want to do a U-RL code before sending a string, you can use S erver. UrlEncode method.

3. The MapPath method 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)

P ath Specifies the relative or virtual path to map the physical directory. If P ATH starts with a forward slash (/) or backslash (\), the M Appath method returns the P ATH as the full virtual path when the path is returned. If P Ath does not start with a slash, the M Appath method returns the same. The path relative to the existing path in the ASP file. Note here that the M Appath method does not check whether the returned path is correct or if it exists on the server.

For the following example, 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 the server variable PATH_INFO to map the physical path of the current file. The following script

<%= 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 relative to the current directory, which is the directory C:\Inetpub\Wwwroot\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 S erver. CreateObject is probably the most practical and powerful feature of SP a. It is used to create a Ctivex component instance that has been registered to the server. This is a very important feature, because by using a Ctivex component you can easily extend the capabilities of a ctivex, it is using the a Ctivex component that you can achieve vital functions such as database connectivity, file access, ad display, and other V bscript that cannot be mentioned For or not simply rely on the functions that can be performed by using A Ctivex alone.    It is because of these components that the SP A has a strong vitality. Its syntax is as follows: Server.CreateObject ("Component Name") by default, by S erver. The CreateObject method creates an object that has a page scope. This means that the server will automatically destroy these objects after the current A-SP page processing completes. If you want to create an object that has a session or application scope, you can use the < object> to mark and set the SCOPE properties of the sessions or application, or you can store the object in a dialog and application variable. The following routine: <% Set session ("ad") = Server.CreateObject ("MSWC.    AdRotator ")%> note here that you cannot create an instance of an object 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 objects of SP A, I wonder if everyone is excited? In fact, a SP is very simple, as long as we continue to practice, I believe that after a period of time is not difficult to become a SP ace. From the next article, the author will begin to introduce the a Ctivex component in SP A, which is a very important and useful part of SP's application. Please pay attention.



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.