This article mainly introduces the relevant information about ASP built-in object server. Friends who need it can refer to it.
Server objects provide access to methods and properties on the server, most of which are served as functional services for utility programs. With Server objects, you can start ActiveX object routines on the server and use Active Server services to provide functions like HTML and URL encoding.
1. Syntax
Server.property|method
2. Attributes
ScriptTimeout timeout value, timeout is processed after the script runs for more than this time. The following code specifies that the server processing script will time out after 100 seconds.
< % Server.ScriptTimeout=100 %>
It should be noted here that the default ScriptTimeout value can be set for the Web service or Web server by using the AspScriptTimeout property in the metadatabase. The ScriptTimeout property cannot be set to less than the value specified in the metadatabase. For example, if NumSeconds is set to 60 and the metadatabase setting contains the default value of 90 seconds, the script timed out after 90 seconds.
3. Method
1. HTMLEncode method
The HTMLEncode method allows you to HTML encode a specific string. Although HTML can display most of the text you write to an ASP file, 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 explain it. For example, the following text:
This is a test of the HTMLEncode method. < br> There should be no other line here.
It will be displayed by the browser as:
This is a test of the HTMLEncode method.
There shouldn't be another line here.
To avoid such problems, we need to use the HTMLEncode method of the Server object, using the corresponding HTML Character Code that is not interpreted by the browser instead of HTML tag characters. Therefore, the following code can display the correct HTMLEncode string, so that the text outputs as you want in the browser.
< %
Response.write Server.HTMLEncode (This is a test of the HTMLEncode method. < br> There should be no new line here.)%>
2. URLEncode method
Just as the HTMLEncode method allows customers to translate strings into acceptable HTML formats, the URLEncode method of the Server object can correctly encode strings according to URL rules, and when string data is passed to the server as a URL, in characters Spaces are not allowed in the string, and special characters are not allowed. To do this, if you want to URL encode before sending the string, you can use the Server.URLEncode method.
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 which the physical directory is to be mapped. If Path starts with a forward slash (/) or backslash (/), the MapPath method returns the path as the complete virtual path. If Path does not start with a slash, the MapPath method returns a path that is the same as 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, the file data.txt and the test.asp file containing the following scripts are both located in the directory C:/Inetpub/Wwwroot/asp. The C:/Inetpub/Wwwroot directory is set as the host directory of the server. The following example uses the server variable PATH_INFO to map the physical path to the current file. The following script
< %= server.mappath(Request.ServerVariables(PATH_INFO))%>
Output
c:/inetpub/wwwroot/asp/test.asp
Since the path parameters in the following example do not start with slash characters, they are relatively mapped to the current directory, here 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 practical and powerful feature in ASP. It is used to create an instance of ActiveX component that has been registered to the server. This is a very important feature because using ActiveX components allows you to easily extend the capabilities of ActiveX. It is precisely with ActiveX components that you can implement critical features such as database connections, file access, advertising displays and others VBScript cannot provide or simply rely on the functionality that can be accomplished by using ActiveX alone. It is precisely because of these components that ASP has 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 is completed, the server will automatically destroy these objects. If you want to create an object with a session or application scope, you can use the <OBJECT> tag and set the SCOPE property of SESSION or APPLICATION, or you can store the object in conversation and application variables. The following routine:
< %Set Session(ad) = Server.CreateObject(MSWC.AdRotator)%>
It should be noted here that an object instance with the same name as the built-in object cannot be created, otherwise, the following script will return an error.
< %Set Response = Server.CreateObject(Response) %>
So far, we have learned all the built-in objects of ASP. I wonder if you are very excited?
In fact, ASP is very simple. As long as everyone continues to practice, I believe that it will not be difficult to become an ASP expert after a period of time.