Recommended: Detailed explanation of ASP's Session object 1. Attribute 1. SessionID The SessionID property returns the user's session identity. When creating a session, the server generates a separate identity for each session. The session identifier is returned as the elongated data type. In many cases, SessionID can be used for WEB page registration statistics. 2. TimeOut Timeout property is the Sessi of the application in minutes.
When using an asp program for web page design, it is mostly because you need to access the database and then display the data to the page. If there is a lot of data, the access speed of the page will slow down. In order to solve this problem, you can use the following techniques to improve the access speed of the page.One of the tips: Improve the efficiency of using Request collections
Accessing an ASP collection to extract a value is a time-consuming and computing resource consuming process. Because this operation contains a series of searches for related sets, this is much slower than accessing a local variable. Therefore, if you intend to use a value from the Request collection multiple times in the page, you should consider storing it as a local variable.
For example, write the code into the following form to speed up the script engine processing:
| strTitle=Request.Form(Title) strFirstName=Request.Form(FirstName) strLastName=Request.Form(LastName) IfLen(strTitle)ThstrTitle=strTitle& IfstrFirstName=ThstrFullName=strTitle&&strLastName ElseifLen(strFirstName)=1Then strFullName=strTitle&strFirstName&.&strLastName Else strFullName=strTitle&strFirstName&&strLastName EndIf |
Tips 2: Direct access to the appropriate collection
If not, don't use strPage=Request(page) to get parameters, because this will search all collections in order—QueryString, Form, Cookies, ClientCertificate, ServerVarible until the first matching value name is found. This is less efficient than directly accessing the appropriate set and is unsafe unless it is absolutely guaranteed that this value will not appear in another set.
For example, it may be desirable to search for the WEB server name that satisfies the client's request, which is accomplished by looking for SERVER_NAME in the Request.ServerVarables collection that appears in each query. However, if other sets also contain values named SERVER_NAME (key names are case-insensitive), when using Request(server_Name), an incorrect result will be obtained. In short, the appropriate collection should be accessed directly as much as possible.
Tips 3: Use the Response.IsClientConnected property before time-consuming operation
Using Response.IsClientConnected is a useful way to observe whether the user is still connected to the server and is loading the web page created by the ASP. If the user disconnects or stops downloading, we no longer need to waste the server's resources to create web pages, because the buffer content will be discarded by IIS. So, for web pages that require a lot of time to calculate or use more resources, it is worth checking at each stage whether the visitor is offline:
...Codetocreate first part of the page IfResponse.IsClientConnectedThen Response.Flush Else Response.End EndIf ...Codetocreatenextpartofpage |
Tips 4: Optimize ADO operations in ASP
Generally speaking, data constitutes the actual content of the WEB site. Therefore, it is very useful to optimize ADO operations to speed up ASP code execution:
a. Select only the columns you want: When opening the ADO record set, the table name (i.e., SELECT*) should not be automatically used unless all columns need to be obtained. Using a separate column means that the amount of data sent to or fetched from the server will be reduced. Even if you need to use all columns, naming each column individually will achieve the best performance, because the server no longer has to interpret the names of those columns.
b. Use stored procedures as much as possible. Stored procedures are pre-compiled programs that contain a ready execution plan, so they execute faster than SQL statements.
c. Use appropriate cursor and lock mode. If all the work is done is to read data from the record set and display it on the screen, then the default forward-only, read-only record set is used. The less work ADO uses to maintain the details of records and locking, the higher the performance of execution.
d. Use object variables. A sure way to improve performance when traversing a record set is to use object variables to point to members in the set. For example:
WhileNotRsGc.EOF Response.Write project name: &RsGc(GcMC)&(Project code: &RsGc(GcCode)&) RsGc.MoveNext Wend |
You can use rewritten as follows to speed up execution:
setGcMc=RsGc(GcMc) setGcCode=RsGc(GcCode) WhileNotrsGc.EOFResponse.Write Project name: &GcMc&(Project code: &GcCode&) RsGc.MoveNext Wend |
The new code creates references to object variables, so object variables can be used instead of actual variables, which means the script engine works less because the number of indexes in the set becomes less.
Tips 5: Don't mix script engines
We know that you can use both VBScript and JScript in ASP pages. However, it is not advisable to use both JScript and VBScript on the same page. Because the server has to instantiate and try to cache two (not one) script engines, this adds to the system burden to some extent. Therefore, from a performance perspective, multiple scripting engines should not be mixed in the same page.
You can try it. The above methods can effectively improve the opening speed of ASP page.
Share: Interpretation of how to correctly use Session object variables in ASP Anyone who uses ASP knows that a Session object stores the information needed for a specific user session, and when a user jumps between pages of the application, variables stored in the Session object are not cleared, and these variables are always present when the user accesses the page in the application. It can reduce the complexity of the program and improve programming efficiency, but it also has many shortcomings.