Under the 20 most commonly used ASP code snippets

Source: Internet
Author: User
Tags website server
11. Is there a way to protect yourself? Source code , Not shown to anyone
A: You can download a Microsoft Windows s cript encoder, which can encrypt ASP scripts and client javas scripts/vbs scripts... However, after the client is encrypted, only ie5 can be executed. After the server script is encrypted, only s runtime engine 5 (installed with ie5) can be executed.

12. How can I transmit a query string from one ASP file to another?
A: response. Redirect ("second. asp? "& Request. servervariables (" QUERY_STRING "))

13. Does the global. Asa file always fail?
A: only when the web directory is set to Web application and global. ASA is valid, and global. ASA is valid under the root directory of a Web application. IIS4 can use Internet Service Manager to set how application setting can make HTM files run scripts like ASP files Code ?

14. How can I make the HTM file execute script code like an ASP file?
Answer: Internet Sevices Manager-> select default web site-> right mouse key-> menu properties-> main directory-> Application Program Application setting> click Configuration> app mapping> Add> executable browse and select \ winnt \ system32 \ inetsrv \ ASP. dll extension input HTM method exclusions input put. delete all. However, it is worth noting that the HTM should also be processed by ASP. dll, reducing the efficiency.

15. How to register Components
A: There are two methods.
Method 1: manually register DLL. This method is used from IIS 3.0 to IIS 4.0 and other Web servers. It needs to be executed in the command line mode, enter the directory containing DLL, and enter: regsvr32 component_name.dll such as c: \ temp \ regsvr32 aspemail. DLL, which registers the specific DLL information into the registry on the server. Then this component can be used on the server, but this method has a defect. After the component is registered using this method, the component must have the permission to execute the DLL by setting the NT anonymous account. In particular, some components need to read the Registry. Therefore, the method of registering this component is to cancel the registration of this DLL only when there is no MTS on the server, and use: regsvr32/u aspobject. DLL example C: \ temp \ regsvr32/u aneiodbc. DLL

Method 2: using MTS (Microsoft Transaction Server) MTS is a new feature of IIS 4, but it provides great improvements. MTS allows you to specify that only privileged users can access components, greatly improving the security settings on the website server. To register a component on MTS, follow these steps:
1) Open the IIS console.
2) Expand 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 "interactive" (if the server often uses administrator login ).
6) Right-click the expanded "components" under the package you just created ". Select "New then component ".
7) Select "install new component ".
8) Find Your. dll file and select next.
To delete this object, select its icon and then delete.
Note: pay special attention to the second method, which is the best way to debug your own component, instead of restarting the machine every time.

16. asp and Access database connection: <% @ Language = Vbs Subnet %>  
<%  
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 Subnet %>  
<%  
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
%>  

Create a record set object:Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL statement, Conn, 3, 218. Common SQL commands:

(1) Data Record Filtering:

SQL = "select * from data table where field name = Field Value Order by field name [DESC]"

SQL = "select * from data table where field name like % 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 n where condition expression"

(3) Delete data records:

SQL = "delete from data table where condition expression"

SQL = "delete from data table" (delete all data table Records)

(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 records of source data table to target data table)

(5) statistical functions of data records:

AVG (field name) returns the average value of a table column
Count (* | field name) statistics on the number of data rows or the number of data rows with values in a column
Max (field name) obtains the maximum value of a table column.
Min (field name) obtains the minimum value of a table column.
Sum (field name) adds the values in the data column

The method for referencing the above functions:

SQL = "select sum (field name) as Alias from data table where condition expression"
Set rs = conn. excute (SQL)

Use RS ("alias") to obtain the calculation value. Use the same method for other functions.

(5) Create and delete data tables:

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 (permanently delete a data table)


19. Method of record set object:

Rs. movenext moves the record pointer down a row from the current position
Rs. moveprevious transfers the record pointer from the current position to a row up
Rs. movefirst move the record pointer to the first row of the data table
Rs. movelast moves the record pointer to the last row of the data table
Rs. absoluteposition = n move the record pointer to the nth row of the data table
Rs. absolutepage = n move the record pointer to the first row of page n
Rs. pagesize = N set N records per page
Rs. pagecount the total number of pages returned Based on pagesize settings
Rs. recordcount total number of returned records
Rs. bof indicates whether the record pointer exceeds the first end of the data table. True indicates yes, and false indicates no.
Rs. EOF indicates whether the returned record pointer exceeds the end Of the data table. True indicates yes, and false indicates no.
Rs. Delete deletes the current record, but the record pointer does not move down
Rs. addnew add record to end of data table
Rs. Update update data table records

Source: 51js.com

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.