ASP

xiaoxiao2021-04-09  451

1. How to use ASP to judge your website's virtual physical path

A: Using the mappath method

the physical path to this virtual website is: <% = server.mappath ("/")%>

2. How do I know the browser used by the user: Use the Request Object Method StrBrowser = Request.ServerVariables ("http_user_agent") if INSTR (Strbrowser, "Msie") <> 0 THEN Response.Redirect ("FormsieOnly.htm" Else Response.Redirect ("FORALL.HTM") END IF

3. How to calculate the average number of repetitions per day Answer: Solution <% StartDate = Datediff ("D", NOW, "01/01/1990") if strdate <0 dam stdate = startdate * -1 avgvpd = int 4 Usercnt) / startdate)%>

Display result <% response.write (avgvpd)%> That is it.this page has been viewed Since November 10,1998

4. How to display a random image <% DIM P, PPIC, DPIC PPIC = 12 Randomize P = INT (PPIC * RND) 1) DPIC = "Graphix / Randompics /" & P & ". GIF"%>

Show

5. How to return to the previous page A: >> Preivous Page

Or with images such as: <% = request.servervariables (>>>>>>

6. How to determine the other party's IP address answer: <% = Request.serverVariables ("remote_addr)%>

7. How to link to a pair of pictures: <% @ languages ​​= VBS cript%> <% response.expires = 0 strimagename = "graphix / errors / errooriamge.gif" response.redirect (strimagename)%>

8. Forced input password dialog box: Put this sentence to the beginning of the page <% response.status = "401 Not Authorized" response.end%> 9. How to transfer variables from one page to another: Hidden Type to transmit variable <% form method = "post" action = "mynextpage.asp"> <% for each item in request.form%> <% s cript language = '' javas cript '> Alert ("<% = Yourvar%>"

11. Is there a way to protect your source code, do not give people an answer: You can download a Microsoft's Windows S Cript Encoder, which can encrypt the ASP script and client JavaS CRIPT / VBS CRIPT script.

12. How to transfer Query String from an ASP file to another: Response.Redirect ("second.asp?")))

13.Global.asa files always don't work reply: Only the web directory is set to Web Application, Global.asa is valid, and the root directory of a web application is valid. IIS can use Internet Service Manager how to make the HTM file like an ASP file to perform script code?

14. How can I make the HTM file like an ASP file can perform script code answer: Internet SEVICES Manager -> Select Default Web Site -> Right Mark -> Menu Properties -> Home -> Application Setting -> Click the button "Configuration" -> App Mapping -> Click the button "Add" -> Executable Browse Select /Winnt/System32/inetsrv/asp.dll Extension Enter the HTM Method Exclusions Enter PUT.DELETE all OK. But it is worth noting that this is also processed by ASP.DLL for HTM, and the efficiency will be reduced.

15. How to register the component A: There are two ways.

The first method: Manually register DLL This method IIS has been used and other web server. It requires you to execute in the command line mode, enter the directory containing the DLL, and enter: regsvr32 component_name.dll, for example C: / temp / regsvr32 aspemail.dll, will register DLL's specific information in the registry in the registry in the server . This component can then be used on the server, but this method has a defect. When the component is registered with this method, the component must have the corresponding setting NT anonymous account with permission to execute this DLL. In particular, some components need to read the registry, so the method of this registration component is only used in the case where there is no MTS on the server. Use: regsvr32 / u aspobject.dll Example C: / Temp / Regsvr32 / u Aneiodbc.dll

Second method: Use the MTS (Microsoft Transaction Server) MTS to allow you to specify that only privileged users can access components, greatly improve the security settings on the website server. The steps to register the components on the MTS are as follows: 1) Open the IIS Management Console. 2) Expand Transaction Server, right-click "PKGS Installed" and select "New Package". 3) Click Create An Empty Package. 4) Naming the package. 5) Specify the Administrator account or use "Interactive" (if the server is often used using administrator). 6) Now use Right-click "Components" after the package you just created. Select "New Ten Component". 7) Select "Install New Component" [B]. 8) Locate your .dll file and select Next to complete. To delete this object, just select its icon, then select Delete. Note: Pay special attention to the second method, it is used to debug the best way to write components, without having to restart the machine each time.

16. ASP and Access Database Connection: <% @ Language = VBS CRIPT%> <% 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 = VBS CRIPT%> <% 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 recordset object: SET RS = Server.createObject ("AdoDb.Recordset") RS.Open SQL statement, conn, 3,218. SQL common command usage method:

(1) Data Record Filter: SQL = "SELECT * FROM Datasheet WHERE Field Name = Field Value ORDER BY Field Name [DESC]"

SQL = "SELECT * FROM DATA WHERE Field Name Like '' '% Field Value%' 'ORDER BY Field Name [DESC]

SQL = "SELECT TOP 10 * FROM DATA 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 WHERE Field Name BetWeen Value 1 AND Value 2"

(2) Update Data Record: SQL = "Update Datasheet Set Field Name = Field Value WHERE Condition Expression"

SQL = "Update Data Table Set Field 1 = Value 1, Field 2 = Value 2 ... Field N = Value N Where Conditions Expression"

(3) Delete data record: SQL = "Delete from Data Sheet WHERE Condition Expression"

SQL = "delete from data table" (deleted all records of data tables)

(4) Add data record: SQL = "INSERT INTO data table (field 1, field 2, field 3 ...) value (value 1, value 2, value 3 ...)

SQL = "INSERT INTO Target Data Table Select * From Source Data Sheet" (Add record of the source data table to the target data table)

(5) Data Recording Statistics: AVG (Field Name) draws a table column average count (* | field name) Statistics on the number of data lines or the number of data line counts on a certain column (field name) Get the maximum value of a table bar min (field name) get the smallest value SUM (field name) plus the value of the data bar

Reference Method for the above function: SQL = "SELECT SUM (field name) AS alias from data table where condition expression" SET RS = conn.excute (SQL)

Use RS ("alias") to get the value, and other functions are used.

The establishment and deletion of the data sheet: CREATE TABLE Table Name (Field 1 Type 1 (Length), Field 2 Type 2 (Length) ...)

Example: Create Table Tab01 (Name Varchar (50), DateTime Default now ())

DROP TABLE Datasheet Name (permanently delete a data sheet)

Record the method of the set object:

Rs.MoveNext moves the record pointer down from the current position down

Rs.MovePrevious moves the record pointer from the current location

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 Moves the record pointer to the data table N

Rs.absolutePage = N Move the record pointer to the first line of the nth page

rs.pagesize = n Sets each page as N records

RS.PageCount Returns the total number of records RS.Recordcount to the total number of records RS.Recordcount according to PageSize

rs.bof returns the record pointer beyond the head end of the data sheet, True is indicated by the false

rs.eof Returns whether the pointer exceeds the end of the data table, True is indicated by the FALSE

Rs.delete deletes the current record, but the record pointer will not move downward

Rs.addnew Add record to the end of the data

Rs.Update Update Data Table Record

20 Recordset object method

Open method

Recordset.open Source, ActiveConnection, Cursortype, LockType, Options

Source RecordSet objects can connect the Command object with the Source property. The Source parameter can be a COMMAND object name, a SQL command, a specified data table name or a Stored ProCedure. If this parameter is omitted, the system uses the Source property of the Recordset object.

ActiveConnection RecordSet objects can connect the Connection object through the ActiveConnection property. The ActiveConnection here can be a connection object or a string parameter containing database configuration (ConnectionsTRING).

CURSORTYPE RECORDSET Object Open method The CURSORTYPE parameter represents what kind of cursor type started data, including AdopenForwardOnly, AdoPENDYNAMIC, and AdoPenStatic, is described below:

Constant constant constant description ADOPENFORWARDONLY 0 default, start a cursor that can only move forward only AdopenKeyset 1 Start a keyset type cursor AdoPENDYNAMIC 2 Start a Dynamic type cursor AdoPenStatic 3 Start a Static Type

The above number of cursor types will directly affect all attributes and methods of the Recordset object, and the following list describes the differences between them.

The RecordSet property where the nextRecordset method does not apply to the Microsoft Access database.

The LockType parameter of the LockType RecordSet object Open method indicates the Lock type to be used. If this parameter is ignored, the system will be preset with the LockType property of the Recordset object. LockType parameter contains adLockReadOnly, adLockPrssimistic, adLockOptimistic adLockBatchOptimistic and the like, as described below: Constant Value Description adLockReadOnly 1 constant default value, the Recordset objects read-only start to run AddNew, Update and Delete adLockPrssimistic 2 or the like when the data source is updated When you temporarily lock the action of other users to keep data consistency AdlockOptimistic 3 When the data source is being updated, the system does not lock other users' actions, and other users can increase, delete, and change the data. AdlockBatchOptimistic 4 When the data source is being updated, other users must change the CURSORLOCATION property to ADUDECLIENTBATCH to increase, delete, and change the data.


New Post(0)