Fully parse server objects

Source: Internet
Author: User

The server object provides methods and attributes for access to the server. Most methods and attributes are provided as functions of the utility.

Syntax:

Server. Property | Method

Property)

The server object has only one attribute: maximum time that the scripttimeout program can run

Method (methods)

Createobject creates an object instance.

Execute to execute an ASP file

Getlasterror returns an error code

Htmlencode converts the specified HTML code.

Mappath converts a relative path to an absolute path.

Transfer sends all current status information to another ASP file

Urlencode converts the specified code in URL format, including Spaces

Server Object Methods

Createobject

Syntax

Server. Createobject (progid)

Parameters

Progid

Specify the name of the component to be created. The format is as follows: [Vendor.] component [. version].

Key points:

Generally, an object created using the server. Createobject method has a page range. This means that this object will automatically disappear after the ASP program on this page is executed.

To create an object with a session or application range, you can use

Execute

The execute method calls an ASP file and executes it, just as the ASP file of this call exists in this ASP file. This is similar to calling classes in many languages.

Syntax

Server. Execute (PATH)

Parameters

Path

Specifies the path of the ASP file to be executed. If it is an absolute path, it must be a directory in the same place as the ASP application ).

Explanations

The server. Execute method provides a way to divide a complex ASP application into small units for execution. In this way, you can create an ASP library, and you can call ASP files in your library whenever you need them. This is a bit like ssi! Hey!

After IIS executes the ASP file based on the specified ASP file path, it will automatically return the previous ASP file. The newly executed ASP file may change the HTTP head. But like other ASP files, an error is reported when the program tries to change the HTTP head!

This path parameter can contain a query information.

If the ASP files to be called and called contain the same subfunctions, these subfunctions only play a role in this ASP file. For example, if the following asp1 and asp2 files contain child functions that discard the program. When asp1 calls asp2, ontransactionabort in asp2 starts to execute. When asp2 is executed, ontransactionabort in asp1 starts to execute.

Asp1:

<% @ Transaction = required %>
<%
Server. Execute ("page22.asp ")

Sub ontransactionabort

Sub ontransactioncommit
%>

Asp2.asp:

<% @
Transaction = required

Sub ontransactionabort

Sub ontransactioncommit
%>

Example

Asp1

<% Response. Write ("I am going to execute asp2 ")
Server. Execute ("/myasps/asp2.asp ")
%>

Asp2

<% Response. Write ("here I am") %>

 

Getlasterror

The getlasterror method returns an asperror object to describe an error message. This method is only applicable before the ASP file sends any content to the user.

Syntax

Server. getlasterror ()

Key Points

If a 500; 100 user error has been defined in an ASP application, it refers to a file suffixed with. asp. In this case, when an error occurs during the program running, the server will automatically send it to the ASP page that is being executed in the form of server. Transfer. The ASP application will effectively handle this error. In addition, this asperror object must be valid, so that you can see the error message provided by the server to change this file!

Generally, the web site is constructed based on the file/IISHelp/common/500-100.asp. You can use it to execute an ASP error. Of course you can define it yourself !. If you want to change to another ASP file to execute these user errors. Then you can use the snap-in.

Note: When IIS discovers an ASP file or an error in the global. Asa file, a 500 or 100 user error is generated. The following programs cannot be executed!

Example

The following three examples demonstrate the user errors caused by different errors. Three errors:

Compilation Error

Running Error

Logical error

The first example proves that a compilation error occurs when IIS tries to include a file. This error is generated because no required parameters are defined in this include file. The second example shows a running error. The program is interrupted because there is no "Next" in the program ". the third example shows a logic error because the program tries to divide it by 0. no!

  
Example 1

<%
Response. Write "hello"
%>

Example 2

<%
Dim I
For I = 1 to 1
NXT
%>

Example 3

<%
Dim I, j
Dim Sum
Sum = 0
J = 0

For I = 1 to 10
Sum = sum + 1
Next

Sum = sum/J
%>

 

Htmlencode

The htmlencode method is used to encode the specified string in HTML.

Syntax

Server. htmlencode (string)
 
 

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.