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 httphead. But like other ASP files, when the program tries to change httphead, 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")
SubontransactionAbort
SubontransactionCommit%>
Asp2.asp:
<% @ Transaction = Required
SubontransactionAbort
SubontransactionCommit%>
EXAMPLE
ASP1
<% Response.write ("IamgoingToexecuteasp2") Server.execute ("/ MyASPS / Asp2.asp")%>
ASP2
<% Response.write ("hereiam")%>
GetLastError
GetLasterror method returns an AspersROrObject to describe an error message. This method only applies to user machine before the ASP file is sent. Syntax
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 asperorObject must be effective so you can see the server to provide you with the error message to change this file!
The general Website 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!
EXAMPLE1
<% response.write "Hello"%>
EXAMPLE2
<% Dimifori = 1TO1NXT%>
EXAMPLE3
<% DIMI, JDIMSUMSUM = 0J = 0
Fori = 1to10Sum = SUM 1NEXT
SUM = SUM / J%>
HTMLENCODE
The HTMLENCode method performs HTML encoding for the specified string.
grammar
Server.htmlencode (String)
Parameter string to be encoded characters
example
The following procedure:
<% = Server.htmlencode ("Theparagraphtag:")%>
The output is:
Theparagraphtag:
Note that the program is executed after the browser is:
Theparagraphtag:
But if you use the "View Source File", the source code is not.
Mappath
The mappath method converts relative path to physical paths on the server
grammar
Server.mappath (PATH)
parameter
Path
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 whether the path exists 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 following example, 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.
Below is Script code:
<% = server.mappath (Request.ServerVariables)%> Show:
C: /inetpub/wwroot/script/test.asp
Because the path parameters are not started in "/" below, it is transformed in the current directory, and 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")%>
shown as:
C: /inetpub/wwrowroot/script/data.txt
C: /inetpub/wwwroot/script/script/data.txt
The following two examples are starting with "/". The following is the contents of Scripts:
<% = server.mAppath ("/ script")%>
shown as:
C: /inetpub/wwrowroot/script/data.txt
C: / inetpub / wwwroot / script
Use "/" or "/" directly to get the main directory of the server:
<% = server.mappath ("/")%>
shown as:
C: / inetpub / wwwroot
C: / inetpub / wwwroot
TRANSFER
The Transfer method will pass all the information on the active ASP file to another ASP file.
grammar
Server.Transfer (PATH)
parameter
Path
The location of the ASP file that will receive information will be received.
Point
When you call Server.Transfer, all built-in object status information is 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
<% DIMSESSVAR1RESPONSE.WRITESSION.SESSIONIDRESPONSE.WRITE ("") "" iamgoingtoasp2 ") Server.Transfer (" / myasps / ask2.asp ")%>
ASP2
<% Response.writestion.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
A default scritpttimeout value will be available on WebSrtvic or Webserver 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%>