The Server object provides access to methods and attributes on the Server. Most of the methods and attributes serve as functional services of the utility. (Iis help translation)
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.
I. Script. ScriptTimeout
After the script has been running for more than a period of time, it is time-out.
Generally, the default script running time on the server is 90 seconds.
You can see in the pop-up box of "Default Web site" in "Internet Information Service", you can also set it by yourself.
Well, the above is not, 900 seconds.
It should be the same as WINXP in the "configuration" dialog box in the "main directory" label.
Before understanding the script running time, let's look at a program. The main function is to calculate the webpage execution time.
<Script language = vbs> <br/> startime = timer () <br/> // The following is the webpage content <br/> for I = 1 to 5000 step 20 <br/> document. write ("<pr width =" & int (500 + I) & "> ") <br/> next <br/> // end time <br/> endtime = timer () <br/> document. write ("Page execution time:" & FormatNumber (endtime-startime) *, 3) & "millisecond") <br/> </script> <br/>
[Ctrl + A select all for copy prompt: you can modify some code before clicking run]
Of course, the corresponding ASP means that the page execution time displayed on many sites is displayed.
1, time. asp
<% Startime = timer () %> <A href = # bot> View the execution time below </a> <% For 1 to 5000 Response. write ("Next %> You can also add other content in the middle. <Br> <% Endtime = timer () %> <A name = bot> </a> <% = FormatNumber (endtime-startime) *, 3) %> millisecond |
If the above program becomes for I = 1 to 5000000
Oh, isn't it because the machine can't respond quickly? That's the script execution time.
In order for the program to execute well, it is time to extend the script execution time.
How to extend? Change the default value? Haha, of course not :)
| <% Server. ScriptTimeout = 110%> |
If the time is set to 90 seconds later than the default value, the current code is: specify that the server will time out after 110 seconds.
In addition, the determination of the script time depends on the program. Generally, it takes about 100 seconds. Even if the script can be executed, users who watch the web page may have made it cross-handed for a long time.
The preceding ScriptTimeout is the unique attribute of the Server object.
2. Server. HtmlEncode
HtmlEncode is one of the methods of the Server object. It allows you to encode a specific string in HTML. Although HTML can display most of the text you write into an ASP file, when you need to actually include the characters used in the HTML tag, you will encounter problems. This is because when the browser reads such a string, it tries to explain it.
Let's look at a program. I want to display code like "" on the page (Appendix: code with spaces)
When I write, you will find that the browser has explained it to me.
The Space Code is: <br> <br/> you will find that all the above Code has been executed. <Br/>
[Ctrl + A select all for copy prompt: you can modify some code before clicking run]
Therefore, this method is used to display some special code.
2, htmlencode. asp
<% Response. write ("this is a test without the HTMLEncode method. <Br> here, a new line indicates that the code is executed. ") %> <Hr> <% Response. write Server. HtmlEncode ("this is a test of the HTMLEncode method. <Br> there should be no other line, that is, the Code is not executed. ") %> |
There are some bugs in many websites and forums. If you don't believe them, you can try them in different forums: You just don't think you're in a hurry. Of course, HtmlEncode is only one of the reasons, the most important thing is the conversion of UBB code. However, I have also solved this problem through debugging.
Debug address see http://www.cnbruce.com/juven/showart.asp
Of course, this problem does not exist in the classic Forum, or you will not see the effect.
Iii. Server. UrlEncode
Just as the HtmlEncode method enables the customer to translate strings into acceptable HTML formats, the UrlEncode method of the Server object correctly encodes strings according to URL rules, when string data is transmitted to the server as a URL, spaces or special characters are not allowed in the string. For this reason, if you wantBefore sending a stringURL encoding. You can use the Server. URLEncode method.
For convenience, let's first take a look at the results sent for processing and then handle the accepted results.
3, urlencode. asp
<% Filepath = request. servervariables ("script_name") %> Accept the value in the URL (the accepted value is not processed and the value is interpreted): <% = request. querystring ("cnbruce") %> <Form action = "<% = filepath %>"> You can enter "</Form> Accept the value in the URL (URL encoded, not executed): <% = Server. urlencode (request. querystring ("cnbruce") %> |
Of course, you will find that, although not executed, "<" is changed to "% 3C", ">" is changed to "% 3E", that is becauseNot processed before sending.
However, we can use the Replace function to reverse these special codes.
4. vurlencode. asp
<% Function tihuan (what) Tihuan = what If not isnull (what) then Tihuan = replace (tihuan, "% 3C", "<") Tihuan = replace (tihuan, "% 3D", "= ") Tihuan = replace (tihuan, "% 3E", "> ") Tihuan = replace (tihuan, "% 26 ","&") Tihuan = replace (tihuan, "% 20 ","") Tihuan = replace (tihuan, "% 3B ",";") Tihuan = replace (tihuan, "% 22 ",""") Tihuan = replace (tihuan, "% 2B", "+ ") Tihuan = replace (tihuan, "% 2F ","/") End if End function %><% Filepath = request. servervariables ("script_name") %> Accept the value in the URL (the accepted value is not processed and the value is interpreted): <% = request. querystring ("cnbruce") %> <Form action = "<% = filepath %>"> You can enter "</Form> Accept the value in the URL (URL encoded, not executed): <% = tihuan (Server. urlencode (request. querystring ("cnbruce") %> |
Oh, actually, I did nothing.It should be processed before sendingBut it is a good example to learn this method :)
4. Server. MapPath
I believe all my friends who have read my "DW2ASP series" are stuck here. DW, after all, is a good entry-level thing, but we need to systematically develop ASP programming, so we should have a good understanding of this.
The MapPath method isSpecified relative or virtual path, IngCorresponding physical directory on the server.
The syntax is as follows:
Path specifies the relative or virtual Path to map to the physical directory. If the Path starts with a forward slash (/) or backslash (\), The MapPath method regards the Path as a complete virtual Path when returning the Path. If the Path does not start with a slash, The MapPath method returns the Path relative to the existing Path in this file. Note the MapPath method.Do not checkWhether the returned path is correct or whether it exists on the server.
Of course, this can be used together with Request. ServerVariables.
5. mappath. asp
Request. ServerVariables ("APPL_PHYSICAL_PATH"): <% = Request. ServerVariables ("APPL_PHYSICAL_PATH") %> <p> Request. ServerVariables ("PATH_INFO"): <% = Request. ServerVariables ("PATH_INFO") %> <p> Request. ServerVariables ("SCRIPT_NAME"): <% = Request. ServerVariables ("SCRIPT_NAME") %> <p> Request. ServerVariables ("URL"): <% = Request. ServerVariables ("URL") %> <p> Request. ServerVariables ("PATH_TRANSLATED"): <% = Request. ServerVariables ("PATH_TRANSLATED") %> The preceding values are extracted from ServerVariables. mapath is used to convert a virtual address into a physical address. <P> Server. MapPath (Request. ServerVariables ("URL"): <% = Server. MapPath (Request. ServerVariables ("URL") %> <p> Or you can write a non-existent path by yourself and execute the command <p> Server. MapPath ("cnbruce. asp"): <% = Server. MapPath ("cnbruce. asp") %> <p> Next "/" <p> Server. MapPath ("/cnbruce. asp"): <% = Server. MapPath ("/cnbruce. asp") %> <br> Server. MapPath ("\ cnbruce. asp"): <% = Server. MapPath ("\ cnbruce. asp") %> <p> You will find that the physical address is changed to the default root directory of IIS. This is where the mappath of a site such as 6to23 is located. It is better to use a virtual host. Even the root node, it is also the default storage node root of its own site. |
Test my address http://www.cnbruce.com/server.asp
Note that the test address and the address under the root directory correspond to the same folder (this is the virtual host), and 6to23 and so on will not be the same.
With this understanding, the processing of the path should be much better, and then return to my site to see how I handle the ath path of the database. I believe it is another level of understanding.
The mappath path of the database is handled in:
Http://www.cnbruce.com/blog/showlog.asp? Cat_id = 27 & log_id = 241
V. Server. CreatObject
Server. CreateObject is probably the most practical and powerful function in ASP. It can be used to create ActiveX component instances registered on the server. This is a very important feature, because the use of ActiveX Components allows you to easily expand ActiveX capabilities, it is the use of ActiveX components, You can implement the vital functions, for example, database connections, file access, AD display, and other vbscripts cannot provide or simply rely on the functions that ActiveX alone can do. It is precisely because of these components that ASP has a powerful vitality.
Haha, but before we talk about database connection, This is blank first. "Well, it's time to go" :) it's not too late when we get in touch with the database connection.
Well, today we have learned about Server objects. It seems like everything is useful and important.
Also, it should be noted that, if you repost from this part, you will find errors with the source part, such as code, & Lt, & gtAnd so on. It indicates that your site has these problems.