Let's share the commonly used ASP programming code:
1. How to judge the virtual physical path of your website with ASP
Answer: Use MAPPATH method: < % = server.mappath (/) %>
2. How do I know the browser used by users?
Answer: Use The request object method:
<%
strbrowser = request.servervariables (http_user_agent)
If Instr (Strbrowser, MSIE) <> 0 THEN
Response.redirect (formsieonly.htm)
Else
Response.redirect (fact.htm)
End if
%>
3. How to calculate the average daily number of repeated visits
Answer: Solution
< % STARTDATE = D, Now, 01/01/1990)
if Strdate <0 thesttartdate = Startdate*-1
avgvpd = int (using)/StartDate) %>
Show results
< % Response.write (AVGVPD) %>
That is it.this page have ben viewed since November 10,1998
4. How to display random images
< % dim p, ppic, DPIC
ppic = 12
randomize
p = int ((PPIC*RND) +1)
DPIC = Graphix/RANDOMPICS/& P & .gif
%>
show
<img src = < % = dpic %>>
5. How to return to the previous page
Answer: <A href = < % = request.servervariables (http_referr) %>> Preivous Page < /a>
Or use pictures such as: <img src = Arrowback.gif Action = "http://www.jzxue.com/wangzhankaifa/asp/201106/mynextpage.asp" Method = "Post">
< % For Each item in request.Form %>
<input namee = < % = item %> type = hidden
value = < % = server.htmlencode (request.form (it)) %>>>
< % Next %>
< /form>
10. Why do I use MSGBOX in ASP programs, the program is wrong and said that there is no permissions
Answer: Since the ASP is run by the server, if you can display a dialog box in the server, then you have to wait for someone to press OK to continue executing, and the general server will not be guarded, so Microsoft has to prohibit this from this. Function, and tell you (haha) without authority. But ASP and client script binding can display a dialog box, as follows:
<%Yourvar = Test dialog box%>
Light rain
11. Is there any way to protect your source code and do not see people
Answer: You can download a Microsoft Windows Script Encoder, which can encrypt the ASP script and client JavaScript/VBScript script. Essence Essence However, after the client is encrypted, only IE5 can be executed. After the server -side script is encrypted, the Script Engine 5 is installed on the server.
12. How can I transmit Query String from one ASP file to another?
Answer: The former file is added: response.redirect (second.asp? & Request.servervariables (query_string))
13.global.asa files always do not work?
Answer: Only web directory is set to web application, global.asa is effective, and Global.asa is effective under the root directory of a web application. IIS4 can use the Internet service manager to set the Application Setting how to make the HTM file execute the script code like an ASP file?
14. How can the HTM file execute the script code like an ASP file?
Answer: Internet sevices manager-> Select the default web site-> right rat button-> Menu attribute-> main directory-> Application setting-> Click button configuration-> App Mapping-> Click the button Add-> Executable Browse select /winnt/system32/ineTsrv/asp.dll extension Enter htm method exclusions and input put.delete. However, it is worth noting that this is also processed by ASP.DLL for HTM, and efficiency will be reduced.
15. How to register a component
Answer: There are two ways.
The first method: manual registration DLL is used from IIS 3.0 to IIS 4.0 and other Web Server. It requires you to execute in the command line, enter the directory containing DLL, and enter: regsvr32 component_name.dll, such as C:/Temp/Regsvr32 Aspemail.dll, it will register the DLL's specific information to the registry in the registry of DLL Essence Then this component can be used on the server, but this method has a defect. When the component is completed using this method, the component must set the NT anonymous account with permissions to execute this DLL. Especially some components need to read the registry, so the method of this registered component is to use the DLL of the registered registration without MTS on the server. /u aneiodbc.dll
The second method: The MTS (Microsoft Transaction Server) MTS is a new feature of IIS 4, but it provides huge improvements. MTS allows you to specify that only users with privileges can access components, which greatly improves the security settings on the website server. The steps of registering components on the MTS are as follows:
1) Open the IIS management console.
2) Expand the transaction server, right -click PKGS Installed and select New Package.
3) Click Create An Empty Package.
4) Name the package.
5) Specify the administrator account or use the Internet (if the server often logs in with Administrator).
6) Now use right -click the components after the package you just established. Select New THEN Component.
7) Select Install New Component.
Find your .dll file and select Next to complete.
To delete this object, just select its icon and select Delete.
Note: In particular, pay attention to the second method. It is the best way to debug the component of the component, without having to restart the machine every time.
16. ASP and Access database connection:
<%@ Language = VBScript%>
<%
dim conn, mdbfile
mdbfile = server.mappath (database name .mdb)
set conn = server.createObject (adodb.connection)
conn.open driver = {microSoft Access Driver (*.mdb)}; uid = admin; pwd = database password; dbq = & mdbfile
%>
17. ASP and SQL database connection:
<%@ Language = VBScript%>
<%
dim conn
set conn = server.createObject (adodb.connection)
Con.open Provider = SQLOLEDB; Data Source = SQL server name or IP address; uID = SA; PWD = database password; database = database name
%>
Establish a record set object:
<%
set rs = server.createObject (Adodb.oldSet)
RS.Oopen SQL statement, conn, 3,2
%>
18. SQL commonly used commands to use:
(1) Data recording screening:
SQL = Select * from data table where field name = field value order by field name [desc]
SQL = Select * from data table where field name is live '%field value%' order by field name [desc]
SQL = SELECT TOP 10 * FROM data table where field name order by field name [desc]
SQL = Select * from data table where field name IN ('value 1', 'value 2', 'value 3')
SQL = SELECT * From Data Table WHERE Field Name Between value 1 and value 2
(2) Update data records:
SQL = Update data table set field name = field value where condition expression
SQL = Update data table set field 1 = value 1, field 2 = value 2 ... field n = value condition expression
(3) Delete data records:
SQL = DELETE FROM Data Table where conditional expression
sql = delete from data table (delete all records of the data table)
(4) Add data records:
SQL = Insert INTO data table (field 1, field 2, field 3 ...) valuess (value 1, value 2, value 3 ...)
SQL = Insert INTO target data table Select * from source data table (add the record of the source data table to the target data table)
(5) Data record statistical function:
AVG (field name) obtains the average value of a table bar
Count (*| Field name) statistics on the number of data rows or statistics on the number of data rows with value on a column
MAX (field name) Get the maximum value of a table bar
MIN (field name) Get the minimum value of a table bar
SUM (field name) adds the value of the data bar
Quote the method of the above functions:
SQL = Select Sum (field name) AS aliases from data table where conditional expression
set rs = const.excute (SQL)
Use RS (alias) to obtain the value of the uniform, and other functions are used above.
(5) The establishment and deletion of the data table:
Create Table data table name (Field 1 type 1 (length), field 2 type 2 (length) ...)
Example: Create Table Tab01 (name varchar (50), datetime default now ()))
Drop table data table name (permanent delete a data table)
19. The method of recording set objects:
RS.movenext will transform the record pointer from the current position
RS.MOVEPREVIOUS will record the pointer from the current position up
RS.Movefirst moves the record pointer to the first line of the data table
RS.MOVELAST moves the record pointer to the last line of the data table
RS.AbSolutePosition = N to move the record pointer to the data table N line N
rs.absolutePage = n will move the record pointer to the first line of the nn page
RS.PAGESIZE = n Setting each page is n records n
RS.PageCount returns the total page number according to the settings of PageSize
RS.Recordcount Return to total number of records
RS.BOF returns the record pointer beyond the head of the data table, True said, whether false is whether
RS.EOF returns the record pointer beyond the end of the data table, True said, whether false is whether
RS.DELETE deletes the current record, but the record pointer will not move downward
rs.addnew adds record to the end of the data table
RS.UPDATE update data table record
20 RecordSet object method
Open method
RecordSet.open Source, ActiveConnection, Cursortype, LockType, Options
Source
The RecordSet object can connect the Command object through the source attribute. Source parameters can be a COMMAND object name, a section of SQL command, a specified data table name, or a Stored Procedure. If this parameter is omitted, the system uses the source attribute of the RecordSet object