ASP Basics Tutorial: ASP built-in Object Server

Source: Internet
Author: User
Tags metabase microsoft website

Through the first nine theories and practice, I believe that we have a systematic understanding of the ASP, although so far, we have only learned the ASP 4 built-in objects, but has been fully able to write some practical small program. Today, the author will continue to explain to you the last ASP built-in object--server.

Before I start this course, I will still be here to answer some of the more common questions raised by my friends. Many friends have recently written to ask me how to build the server-side Active server Page environment. I think it may be that I did not speak clearly in the previous few, so it is necessary to elaborate on this question at the beginning of this article.

The ASP's application is based entirely on Microsoft Internet infomation Server (IIS), and IIS has two versions for Windows NT server and WorkStation (and of course IIS4.0 Windows98 version, which is not mentioned here for the moment), its function is almost identical, the difference is just the installation process. In general, we are using the IIS version on the NT server. In an NT Server environment, publishing information and managing the site is typically done through IIS. Typically we run version IIS2.0 in the NT4.0 release, but it does not have the functionality to support ASP. ASP must be installed separately after installing IIS, the installation file is a Microsoft released ASP installation package, about 9 trillion, should be able to download on the Microsoft 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 change, but simply increased the ability to run the ASP. When the installation is complete, run Internet Services Manager and you will see the following screen:

  

There are three services available in IIS3.0: WWW, Gopher, ftp,www Services submit WEB pages for the customer's browser, and allow customers to access. asp files. Of course, you can install the latest version of IIS4.0 directly, and the author also advises you to install this version because it has stronger WEB management capabilities and security. In IIS4.0, the management interface of IIS has fundamentally changed, and the familiar Internet Service Manager is replaced by the Microsoft Management console, referred to as MMC. The interface is as follows:

  

So how to install IIS4.0? When installing IIS4.0 on NT4.0, you must have NT SP3 installed on your system, and Internet Explorer4.01, note that the version of Internet 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 IIS4.0. The author deliberately spent an evening upgrading IE versions on Microsoft's site in order to install the version.

IIS supports virtual directories that can be managed by using the Directory tab in the Server Properties dialog box. Establishing a virtual directory is very important for managing your WEB site. First, the virtual directory hides important information about the structure of the site directory. 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 in the WEB page, it will expose important information about the site directory, which can lead to the system being 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 means that directory content is passed from IIS to the browser. Performing an access allows executable files to be executed within that directory. When you need to use ASP, you must set your. asp file's directory to "Excute (execute)". The author recommends that when you set up the Web site, HTML files are placed in separate directories from the ASP files, and then the HTML subdirectory is set to "read", and the ASP subdirectory is set to "execute", which not only facilitates the management of the web, but most importantly improves the security of the ASP program and prevents The program content is accessed by the customer. Because at the end of July this year IIS was discovered by some network experts a terrible bug, that is, when you in a site of the. asp file after adding:: $DATA, the customer 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 readable. {Shanghai Treatment Impotence Hospital Editing}

I think, now you should be fully aware of the ASP server-side settings, below we go to the point-learning 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 a function of the utility. With the server object, you can start an ActiveX object routine on the server and use the Active Server service to provide functions such as HTML and URL encoding.

First, the grammar

Server.property|method

Second, the attribute

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

<% server.scripttimeout=100%>

It is important to note that you can set the default ScriptTimeout value for a Web service or Web server by using the AspScriptTimeout property in the metabase. The ScriptTimeout property cannot be set to less than the value specified in the metabase. For example, if Numseconds is set to 60 and the metabase setting contains the default value of 90 seconds, the script times out after 90 seconds.

Third, the method

1. HTMLEncode method

The HTMLEncode method allows you to HTML-encode a particular string, although HTML can display most of the text you write to an ASP file, but you will encounter problems when you need to actually include the characters used in the HTML markup. 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 not be another line here.

will be displayed by the browser as:

This is a test of the HTMLEncode method.

There should not be another line here.

To avoid such problems, we need to use the HTMLEncode method of the Server object to replace the HTML tag character with the corresponding Htmlcharacter Code that is not interpreted by the browser. So, to display the correct HTMLEncode string in the following code, output the text as you want in the browser.

<%

Response.Write Server.HTMLEncode ("This is a test of the HTMLEncode method. < br> there should not be another line here. ")

%>

2. UrlEncode method

Just as the HTMLEncode method enables customers to translate strings into acceptable HTML formats, the UrlEncode method of the Server object can correctly encode strings based on URL rules, which are not allowed in strings when string data is passed to the server as a URL Spaces, and special characters are not allowed. To do this, you can use the Server.URLEncode method if you want URL encoding before the string is sent.

3. MapPath method

The MapPath method maps the specified relative or virtual path to the appropriate physical directory on the server.

The syntax is as follows: Server.MapPath (Path)

path Specifies the relative or virtual path of the physical directory to be mapped. If path starts with a forward slash (/) or backslash (\), the MapPath method returns the path as a complete virtual path. If path does not start with a slash, the MapPath method returns the path relative to the path already in the. asp file. It is important to note that the MapPath method does not check whether the returned path is correct or exists on the server.

For the following examples, file data.txt and test.asp files that contain the following scripts are located under 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

Server.CreateObject is probably the most practical and powerful feature in the ASP. It is used to create an instance of an ActiveX component that is already registered with the server. This is a very important feature, because using ActiveX components allows you to easily extend the ability of ActiveX, and it is with the use of ActiveX components that you can implement critical features such as database connectivity, file access, ad display, and other VBScript Cannot provide or simply rely on the functionality that can be accomplished by using ActiveX alone. It is because these components make the ASP has a strong vitality.

Its syntax is as follows:

Server.CreateObject ("Component Name")

By default, objects created by the Server.CreateObject method have a page scope. This means that 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 < object> tag and set the SCOPE property of the session or application, or you can store the object in a dialog and application variable. The following routines:

<% Set Session ("ad") = Server.CreateObject ("MSWC"). AdRotator ")%>

It is important to 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 the ASP all the built-in objects, I do not know everyone is not very excited? In fact, ASP is very simple, as long as we continue to practice, I believe that after a period of time is not difficult to become a master of the ASP. From the next article, the author will begin to introduce the ASP built-in ActiveX components, which is a very important and practical part of ASP application. Please pay attention.

ASP Basics Tutorial: ASP built-in Object Server

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.