ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

ASP SCRIPTING

The server Object

     The Server Object provides access to methods and properties on the server. Most of these methods and properties serve as utility functions. This object is very useful to perform tasks such as encode URLs or HTML, set server environments, etc. It can also create objects from server components that can be used to do various other tasks, like connect to a database.

  The ScriptTimeout Property

     The Server Object has only one property, the ScriptTimeout property. This property sets the maximum amount of time that a script can run for before it times out. Beyond this limit, the script is terminated. Note that this is true only for scripts and not server components. This is useful to prevent deadlocks in the application. If a script keeps running forever (like a Do While loop for which the developer set an invalid exit condition), it could crash the server. The default value is 90 seconds. The syntax to access the ScriptTimeout is:

Server.ScriptTimeout 

Example:
<% Response Write (Server. Script.Timeout) %> 

To set the ScriptTimeout, use the following syntax: 

Server.ScriptTimeout = <Number of seconds> 

Example:
<% Server ScriptTimeaut 60 %> 


  Methods of the Server Object

     The Server Object has four methods; CreateObject, HTMLEncode, Mappath and URLEncode. These are discussed below.

  The CreateObject Method

     This method creates instances of server components, allowing them to be used in the script. A few of the components bundled into the server by default are Ad Rotator, Browser Capabilities, Content Linking, File Access Component, Database Access

Component, Content Linking, etc. The syntax for this is:

Server.Create0bject("<Object>")

The instance of the object would be assigned to an object variable, as illustrated in the following example:

<% Set dbs = Server.CreatedObject("ADODB.Connection")%>

  The HTMLEncode Method

     This method applies HTML encoding to a string. Any string value that is passed to this method is output to the HTML stream in a way that none of the characters would be confused by the client browser. For example, if you wish to display the HTML source of a page, you can pass that entire string to this method. All characters that might cause problems, like angular brackets, are replaced with their respective HTML codes. The syntax for this is:

Server.HTMLEncode("<String>")

  The MapPath Method

     This method maps the virtual directory of your application to the physical directory on the file system. This means that if your application is in C:\Inetpub\wwwroot\asp (as configured in IIS), this method would map the virtual directory asp as the root of the application. The syntax is:

Server.Mappath ("<Path>")

     If path starts with either a forward slash or a backslash, the method returns the root of the virtual directory. If path does not start with a slash, the method returns a path relative to the current directory of the .asp file being processed. The MapPath method does not support relative path syntax (. or ..). Also, the method does not check whether the path it returns is valid.

C:\Inetpub\wwwroot

  The URLEncode Method

     Like the HTMLEncode method, the URLEncode method applies URL encoding to a specified string. This is useful for constructing query strings and Cookies. This replaces all characters that are not valid in URLs with their valid URL code substitutes. 

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here