server| objects
The server object provides access to methods and properties on the server. Most of these methods and properties are serviced as functionality of the utility.
Grammar
Server.property|method
ScriptTimeout
The ScriptTimeout property specifies how long the script can run maximum before it ends.
When the server component is processed, the time-out limit is no longer in effect.
Grammar
Server.ScriptTimeout = Numseconds
Parameters
Numseconds
Specifies the maximum number of seconds a script can run before being terminated by the server. The default value is 90 seconds.
Comments
You can set the default ScriptTimeout value for a Web service or Web server by using the AspScriptTimeout attribute 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 10, and the metabase setting contains a default value of 90 seconds, the script times out after 90 seconds. However, if the numseconds is set to 100, the script times out after 100 seconds.
For more information about using the metabase, see About metabase.
Example
In the following example, if the server processing script exceeds 100 seconds, it will timeout.
<% server.scripttimeout =%>
The following example gets the current value of the ScriptTimeout property and stores it in the variable TimeOut.
<% TimeOut = Server.ScriptTimeout%>
CreateObject
The CreateObject method creates an instance of the server component. If the component executes the OnStartPage and OnEndPage methods, the OnStartPage method is invoked at this point.
Grammar
Server.CreateObject (ProgID)
Parameters
ProgID
Specifies the type of object to create. The ProgID format is [vendor.] component[. Version].
Comments
By default, objects created by the Server.CreateObject method have page scopes. This means that after the current ASP page processing completes, the server will automatically destroy these objects.
To create an object that has a session or application scope, you can use the <OBJECT> tag and set the SCOPE properties of the sessions or application, or you can store the object in a dialog and application variable.
For example, in the script shown below, when the session object is corrupted, the object stored in the conversation variable will also be corrupted when the dialog times out or when the Abandon method is invoked.
<% Set session ("ad") = Server.CreateObject ("MSWC. AdRotator ")%>
You can break an object by setting the variable to Nothing or a new value, as shown below. The first example releases AD objects, and the second example uses strings instead of AD.
<% session ("ad") = Nothing%>
<% session ("ad") = "Other Valum"%>
You cannot create an object instance with the same name as an Builtin object. For example, the following script will return an error.
<% Set Response = Server.CreateObject ("Response")%>
Example
<% Set Myad = Server.CreateObject ("MSWC. AdRotator ")%>
The example above creates a MSWC named Myad. AdRotator server components, MSWC. The AdRotator component can be used for automatic rotation of advertisements on Web pages.
HTMLEncode
The HTMLEncode method applies HTML encoding to the specified string.
Grammar
Server.HTMLEncode (String)
Parameters
String
Specifies the string to encode.
Example
Script
<%= Server.HTMLEncode ("The paragraph tag: <P>")%>
Output
The paragraph tag: <P>
Note that the above output will be displayed by the Web browser as
The paragraph tag: <P>
If you look at the source file or open a Web page as text, you can see the encoded HTML.
MapPath
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
Grammar
Server.MapPath (Path)
Parameters
Path
Specifies the relative or virtual path to map the physical directory. If path starts with a forward slash (/) or backslash (\), the MapPath method treats the path as the full virtual path when it returns the paths. If path does not start with a slash, the MapPath method returns the path relative to the path already in the. asp file.
Comments
The MapPath method does not support relative path syntax (.) or (..). For example, the following relative paths ... /mydir/myfile.txt returns an error.
The MapPath method does not check whether the returned path is correct or exists on the server.
Because the MapPath method maps only the path, regardless of whether the specified directory exists, you can first map the path to the physical directory structure with the MapPath method, and then pass it to the component that creates the specified directory or file on the server.
Example
For the following example, file Data.txt and test.asp files containing the following scripts are located under the directory C:\Inetpub\Wwwroot\Script. 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. Script
<%= Server.MapPath (Request.ServerVariables ("Path_info"))%>
Output
C:\inetpub\wwwroot\script\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 C:\Inetpub\Wwwroot\Script. Script
<%= Server.MapPath ("Data.txt")%>
<%= Server.MapPath ("Script/data.txt")%>
Output
C:\inetpub\wwwroot\script\data.txt
C:\inetpub\wwwroot\script\script\data.txt//aspxuexi.com
The next two examples use the slash character to specify that the returned path should be treated as a full virtual path on the server. Script
<%= Server.MapPath ("/script/data.txt")%>
<%= Server.MapPath ("\script")%>
Output
C:\inetpub\script\data.txt
C:\inetpub\script
The following example shows how to use a forward slash (/) or backslash (\) to return the physical path of the host directory. Script
<%= Server.MapPath ("/")%>
<%= Server.MapPath ("\")%>
Output
C:\inetpub\wwwroot
C:\inetpub\wwwroot
UrlEncode
The UrlEncode method applies the URL encoding rule, including the escape character, to the specified string.
Grammar
Server.URLEncode (String)
Parameters
String
Specifies the string to encode.
Example
Script
<%response.write (Server.URLEncode ("http://www.microsoft.com"))%>
Output
Http%3a%2f%2fwww%2emicrosoft%2ecom