ASP's built-in Object server

Source: Internet
Author: User
Tags execution iis relative servervariables urlencode root directory

The server object provides access to methods and properties on the server, where most of the methods and properties serve as functional services for 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.

  One, Script.scripttimeout

After the script runs for more than a period of time, the timeout is processed. The server general default script run time is 90 seconds. As you can see from the Properties pop-up box in the default Web site in Internet Information Services, you can also set it yourself.

Oh, the above is not, 900 seconds. It should be the same as WinXP in the Configuration dialog box in the Home Directory tab.

Before understanding the script run time, first look at a program, the main function is to calculate the Web page execution time.

<script language=vbs>
Startime=timer ()
Following is the content of the Web page
For i= 1 to 5000 step 20
document.write ("Next
End time
Endtime=timer ()
document.write ("Page Execution Time:" &formatnumber (Endtime-startime) *1000,3) & "MS")
</script>

Of course, the corresponding ASP is to see many sites have page execution time display

1,time.asp

<%startime=timer ()%>
<a href= #bot > to below to see the execution time </a>
<%
For i= 1 to 5000
Response.Write ("Next
%>
Of course, the middle can add other content. <br>
<%endtime=timer ()%>
<a name=bot></a>
<%=formatnumber ((endtime-startime) *1000,3)%> ms

So if the above program becomes for i= 1 to 5000000

Oh, is not the machine quick reaction does not come over the feeling, that this is the execution time of the script.

In order for the program to perform well, the execution time of the script should be extended.

How long? Change the default? Oh, of course not:)

<%Server.ScriptTimeout=110%>

The time set of course if than the default 90 seconds large, now the code is: Specify the server processing script in 110 seconds after the timeout.
Also, the determination of the script time to see its own program, the general situation of 100 seconds or so almost, even if it can be carried out, the person may be watching the Web page has already fork it.

The above scripttimeout is the server object unique attribute

Second, Server.HTMLEncode

HTMLEncode is one of the methods of the server object. It allows you to encode HTML for a particular string, although HTML can show most of the text you write to the ASP file, but you will have 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.

Or look at a program, I want to display "" in the Page "" Code (with: is a space code) then when I write, you will find that the browser has explained to me.

The code for the space is:

You will find that the above code has been executed.

So, in order for some special code to be displayed, use this method.

2,htmlencode.asp

<%response.write ("This is not a test using the HTMLEncode method.") <br> here is another line that shows that the code is executed. ")%>
<%response.write Server.HTMLEncode ("This is a test of the HtmlEncode method.) <br> this should not be another line, that is, the code has not been executed. ")%>

This in many sites, forums exist some bugs, do not believe you can go to the forum to try: Typing is not, nasty to die you: Of course, HTMLEncode is just one of the reasons, the most important thing is the conversion of UBB code. But I have also been debugging to solve this.

Three, Server.URLEncode

Just as the HtmlEncode method enables customers to translate strings into acceptable HTML formats, the Server object's UrlEncode method encodes 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.

For the sake of convenience, we look first at handling the delivery and then processing the accepted effect.

3,urlencode.asp

<%filepath=request.servervariables ("Script_name")%>
Accept the value in the URL (no processing accepted value, Discovery value interpreted): <%=request.querystring ("WEBJX")%>
<form action= "<%=filepath%>" >
You can enter "</form>
Accept the value in the URL (urlencode encoded and not executed): <%=server.urlencode (Request.QueryString ("WEBJX"))%>

Of course you will find that, although not executed, but will appear "<" into "%3c", ">" has become "%3e", that is because it is not processed before sending. However, we can also reverse these special codes through the Replace function.

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 (no processing accepted value, Discovery value interpreted): <%=request.querystring ("WEBJX")%>

<form action= "<%=filepath%>" >
You can enter "</form>
Accept the value in the URL (urlencode encoded and not executed): <%=tihuan (Server.URLEncode (Request.QueryString ("WEBJX"))%>

Oh, in fact, above I do not work, the real should be sent before the deal, but for the study of the method of example is a good way:

Four, Server.MapPath

The MapPath method, in particular, maps the specified relative or virtual path to the corresponding physical directory on the server.
Usage, which is 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 this file. It should be noted here that the MapPath method does not check whether the returned path is correct or exists on the server.

Of course this can be connected with request.servervariables use to see.

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 above are extracted through the ServerVariables value, the following to use the Mapath to convert a virtual address to the actual physical address. <p>
Server.MapPath (request.servervariables ("url")): <%=server.mappath (request.servervariables ("url"))%><p >
Or you can write a non-existent path, the same ability to perform <p>
Server.MapPath ("webjx.asp"): <%=server.mappath ("webjx.asp")%><p>
One more "/" <p>
Server.MapPath ("/webjx.asp"): <%=server.mappath ("/webjx.asp")%><br>
Server.MapPath ("\webjx.asp"): <%=server.mappath ("\webjx.asp")%><p>

You will find that the physical address is under the IIS default root directory.
This is the problem with sites like 6to23 MapPath. Or the virtual host is good, even if the root, it is also the default storage node root site.

Note the address of the test and the address under the root directory, corresponding to the same folder (this is the virtual host), 6to23 and the like are not the same.

Have this understanding, the processing of the path should be much better, and then return to my site, see my database MapPath path processing method, I believe it is a level of understanding.

Five, Server.creatobject

Server.CreateObject This method is probably the most practical ASP, but also the most powerful function. It can be used to create instances of ActiveX components that have 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 also because these components make the ASP has a strong vitality.

Well, today, the main server object to learn, feel like it is every useful, important AH. Also, need to explain, if you reprint from this place, the discovery and the source piece has the mistake, for example code, <, &gt and so on, basically is carried out. All indicate that there are problems with your site.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.