Server objects provide methods and properties to access to the server. Most methods and properties are provided as a utility feature.
grammar:
Server.property | Method
Property
Server object has only one attribute: the maximum time of the scripttimeout program is running
Methods
CREATEOBJECT creates an object instance.
Execute executes an ASP file
GetLastError returns an error code
HTMLENCode converts the specified HTML code.
MAPPATH converts a relative path into an absolute path.
Transfer sends the current state information to another ASP file
Urlencode transforms the specified code in the form of URL, including spaces
Method of Server object details
CreateObject
grammar
Server.createObject (ProgID)
parameter
PROGID
Specifies the component name to be created, the format is as follows: [vendor.] Component [.version].
Important:
In general, the object created by the server.createObject method has the range of the page. This is said that this object will automatically disappear when the ASP program is executed.
In order to create an object with a session or Application range, you can use in the global.asa file
EXECUTE
The execute method calls an ASP file and executes it like this ASP file in this ASP file. This is much like the calls in many languages.
grammar
Server.execute (PATH)
parameter
Path
Specifies the path to the ASP file executed. If it is an absolute path, it must be a place (catalog) as this ASP application.
explain
The Server.execute method provides a method of dividing a complex ASP application to a small block unit. In this way, you can build an ASP library, you can call an ASP file in your library when you need it. This is a bit like SSI! Hey!
When IIS performs this ASP file according to the specified ASP file path, the previous ASP file is automatically returned. This ASP file just implemented may change HTTP head. But like other ASP files, when the program is trying to change HTTP Head, it will report an error!
This PATH parameter can include an inquiry information.
If the same subfunction is contained in the ASP files called and call, then these subunies work only in this ASP file. For example, if there is a sub-function of the abandon program in both ASP1 and ASP2 below. First, ASP1 calls ASP2, then on the onTransactionAbort in ASP2 starts, when the ASP2 is executed, OntransactionAbort in ASP1 began execution.
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 / ask2.asp")%> ASP2 <% response.write ("Here I am")%> getLastError
GetLasteError method returns an Asperor Object to describe an error message. This method only applies to user machines before the ASP file is sent.
grammar
Server.getlasterror ()
Point
If a 500; 100 user error has been defined in an ASP application, it refers to a file that is .asp is a file. In this case, when an error occurs when an error occurs when an error occurs, the server will be automatically transmitted to this ASP page in SERVER.TRANSFER. The ASP application will effectively process this error. In addition, this asperror object must be effective so you can see the error message provided by the server to change this file!
The general web site is constructed based on file /iishelp/common/500-100.asp. You can use it to perform an ASP error, of course you can define it yourself! . If you want to change to another ASP file to execute these users' errors. Then you can use Snap-in in IIS.
Note: When IIS discovers an ASP file or an error in the Global.asa file, then a 500; 100 user error is generated. The following programs will not be implemented!
EXAMPLE
The following three examples demonstrate that different errors will generate user errors. Three errors are:
Compile Error
Run error
logical error
The first example demonstrates a compilation error, which is generated when IIS is attempted to contain a file. This error will result because there is no defined parameters in this included file. The second example shows a run error. The reason for this program is interrupted is that there is no "next" in the program. The third example shows a logical error, because this program is trying to divide it 0. No!
EXAMPLE 1 <%> 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%>
The HTMLENCode HTMLENCode method performs HTML encoding for the specified string. Syntax Server.htmlencode (String) Parameters String The following programs below: <% = Server.htmlencode ("The paragraph tag:")%> The output is: The Paragraph Tag: Note After the program is executed, it is: The paragraph tag: But if you use the "View Source File" to look at it, the source code is not.
The mappath mappath method converts relative paths to the physical path syntax server.mappath (path) parameter path on the server relative path. This path is the path that starts with "/" or "/" if there is no "/" in this path, then the mappath method returns the path based on the current directory. Explain the mappath method cannot check if the path is present under this server. Whether this path is present under this server because the mappath conversion path is present. You can use it to convert a relative path to a physical path, and then do various operations under this path. Example In the example below, the Data.txt file has a C: / INETPUB / WWWROOT / SCRIPT directory, and a Test.asp file includes the following code. C: / inetpub / wwwroot is the main directory of the server. In the following example, the physical path of the current file is first obtained by "Path_info" in the environment variable. The following is Script code: <% = server.mappath (Request.ServerVariables)%> Display: c: /inetpub/wwroot/script/test.asp Because the path parameters are not "/" because of the following example The beginning, so it is transformed in the current directory, the ASP file is placed in c: / inetpub / wwwroot / script. The following is the contents of Scripts: <% = server.mAppath ("Data.txt")%> <% = Server.mappath ("script / data.txt")%> Displayed as: c: /inetpub/wwwroot/script/data.txt c: /inetpub/wwwroot/script/script/data.txt The two examples of the following are the following examples below At the beginning of "/". The following is the contents of Scripts: <% = server.mappath ("/ script")%> Displayed as: c: /inetpub/wwwroot/script/data.txt c: / inetpub / wwwroot / script Use "/" or "/" to get the main directory of the server: <% = server.mappath ("/")%> Show: c: / inetpub / wwwroot c: / inetpub / wwwroot transfer Transfer method An all information on the ASP file being executed is passed to another one ASP file. The syntax server.transfer (path) parameter Path will receive the location of the ASP file of the information. Point Point When you call Server.Transfer, all built-in object status information will be included in this transmission. That is to say, all information saved in Session or Application will be transmitted, and all current request information is accepted by the ASP file of the received information. Example The following example demonstrates the example of transferring from an ASP file to another!
ASP1 <% DIM sessvar1 response.write session.SessionId Response.write ("I am Going to ASP2") Server.Transfer ("/ MyASPS / asp2.asp")%> ASP2 <% response. Write session.SessionID%> Urlencode
The URLENCode method can make the specified string URL encoding.
grammar
Server.urlencode (String)
parameter
String Specifies the string to be converted
EXAMPLE
Below is the code:
<% Respones.write (Server.urlencode ("http://www.microsoft.com"))%>
shown as:
HTTP% 3A% 2F% 2Fww% 2EMICROSOFT% 2ECOM
Property: ScriptTimeout
The ScriptTimeout property specifies the maximum running time of the program.
grammar
Server.scripttimeout = NUMSECONDS
parameter
Numseconds
The maximum runtime (in seconds) of the program is specified. The default is 90 seconds
Remarks
The value of a default scritpt timeout will be available on the web sertvic or web server through the AspscriptTimeout property. In the program, the value of the ScriptTimeout property cannot be smaller than this default. For example, if we are set to 10 seconds, and the default value is 90 seconds, then the program will abort the next 90 seconds, not after 10 seconds. Similarly, if we set the value of ScriptTimeOut for 100 seconds, then the program will abort after 100 seconds, not 90 seconds.
EXAMPLE
The following example has been automatically aborted after 100 seconds.
<% Server.scripttimeout = 100%>
The following example will be re-received the value of ScriptTimeout, and then there is a Timout variable
<% Timeout = Server.ScriptTimeout%>