The server object provides access to methods and properties on the server, where most of the methods and properties are serviced as functionality of the utility. With the server object, you can start ActiveX object routines on the server and use the Active Server service to provide functions such as HTML and URL encoding.
First, the grammar
Server.property|method
Second, the property
ScriptTimeout timeout value, which is timed out after the script runs beyond that time. The following code specifies that the server processing script times out after 100 seconds.
<% server.scripttimeout=100%>
It is worth noting that by using the AspScriptTimeout property in the metabase, you can set the default ScriptTimeout value for the Web service or Web server. The ScriptTimeout property cannot be set to less than the value specified in the metabase. For example, if Numseconds is set to 60, and the metabase setting contains a default value of 90 seconds, the script times out after 90 seconds.
Third, the method
1, HTMLEncode method
The HTMLEncode method allows you to encode HTML for a particular string, although HTML can display most of the text you write to the ASP file, but you will encounter problems when you need to actually include the characters used in the HTML tag. This is because when the browser reads such a string, it tries to interpret it. For example, the following text:
This is a test of the HTMLEncode method. < br> there should be no other line here.
will be displayed by the browser as:
This is a test of the HTMLEncode method.
There should not be another line here.
To avoid such problems, we need to use the HTMLEncode method of the Server object to replace the HTML tag character with the corresponding HTML Character Code that is not interpreted by the browser. So, use the following code to display the correct HTMLEncode string so that you can output text in your browser as you want.
<%
Response.Write Server.HTMLEncode ("This is a test of the HTMLEncode method.) < br> there should be no other line here. ")%>
2, UrlEncode method
Just as the HTMLEncode method enables the customer to translate strings into acceptable HTML formats, the Server object's UrlEncode method can encode the string correctly according to the URL rules and is not allowed in strings when the string data is passed to the server as a URL Spaces, and special characters are not allowed. To do this, you can use the Server.URLEncode method if you want to encode the URL before sending the string.
3, MapPath method
The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.
The syntax is as follows : Server.MapPath (Path)
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. It should be noted here that the MapPath method does not check whether the returned path is correct or exists on the server.
For the following example, file Data.txt and test.asp files containing the following scripts are located under the directory C:\Inetpub\Wwwroot\asp. 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. The following script
<%= Server.MapPath (Request.ServerVariables ("Path_info"))%>
Output
C:\inetpub\wwwroot\asp\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 the directory C:\Inetpub\Wwwroot\asp. The following script
<%= Server.MapPath ("Data.txt")%>
<%= Server.MapPath ("Asp/data.txt")%>
Output
C:\inetpub\wwwroot\asp\data.txt
C:\inetpub\wwwroot\asp\asp\data.txt
4, CreateObject method
Server.CreateObject is probably the most useful and powerful function of ASP. It is used to create an instance of an ActiveX component that has been registered to the server. This is a very important feature, because by using ActiveX components you can easily extend the ability to ActiveX, it is with ActiveX components that you achieve vital functions such as database connectivity, file access, ad display, and other VBScript Inability to provide or simply rely on functionality that can be accomplished by using ActiveX alone. It is because of these components that the ASP has a strong vitality.
The syntax is as follows:
Server.CreateObject ("Component Name")
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. If you want to create an object that has a session or application scope, you can use the < object> to mark and set the SCOPE properties of the sessions or application, or you can store the object in a dialog and application variable. The following routine:
<% Set session ("ad") = Server.CreateObject ("MSWC.") AdRotator ")%>
Note here that you cannot create an instance of an object with the same name as the built-in object, otherwise, the following script will return an error.
<% Set Response = Server.CreateObject ("Response")%>
So far, we have learned the ASP all the built-in objects, do not know that everyone is not very excited?
In fact, ASP is very simple, as long as we continue to practice, I believe that after a period of time is not difficult to become an ASP master.