Encapsulation | Encapsulation Abstract The main introduction is to use VB to encapsulate ASP code into DLL to protect ASP code and speed up the implementation of ASP code, save the resources of the server
Keyword Asp,dll, programming
First, the introduction
The server-side scripting environment, which is simple to use, does not require compilation and connectivity, can run directly on the server side, and it supports multi-user, multithreading, and is widely used in web development. Server-side components differ from the client's components. The client component is transmitted over the network, relies on HTML to function, and can only be useful on IE. But the server-side component is running on the server side, and it performs various operations on the server. As a result, all browsers can enjoy it, depending on the server rather than the browser. However, because the ASP script is a plain text format, a malicious person can easily see the content of a page that should not otherwise be seen through the source code. Therefore, it is very important to protect the ASP source code. Encapsulating ASP code into DLLs not only speeds up the execution of ASP code, but also protects the original code. When IIS is requested to execute an ASP program, it first finds the code between the <%%> tags in the ASP file, and executes it (or it can be code between <script runat=server></script>). If the ASP program was previously invoked, it would use an in-memory compiled program to return the HTML code to the user, and if not, it would recompile. This greatly saves the resources of the server.
Ii. Methods of implementation
Start your VB and choose an ActiveX icon. This icon can be found in the new project! VB will provide a default project name (Project1) and class name (Class1). Before you start, make sure that we have the Microsoft ActiveX Data Object 2.0 Library, which is very useful in our program. Select project from the menu, and then select References in which the References window will appear to select the Microsoft ActiveX Data Object 2.0 Library.
Now we have our own engineering (PROJECT1) and class name (Class1). Later we will use their names in the ASP code to refer to this component. In the ASP, we are quoted as follows:
Set objreference = Server.CreateObject ("Projectname.classname")
In order to use the ASP method in a class, you must write both the initial and the terminating functions in this class. Enter the following code: Private Sub Class_Initialize () and Private Sub Class_Terminate () in Class1.cls in the list of programs.
The key functionality in the ASP code is made into a dynamic link library (. dll), partially hiding the ASP source code. For example, the code entered in the Global.bas and class1.cls in the list of programs (the primary function of the code is to retrieve the records in the database and display them).
In the VB drop-down menu, select file → generate article.dll→ Select the directory to save. Locate the Article.dll copy it to the system disk System32 folder, and the last step to register the DLL file. Select Run input regsvr32 c:\winnt\system32\article.dll from the Start menu.
Iii. List of procedures
Code in Global.bas:
Public Objcontext as ObjectContext
Public application as Asptypelibrary.application
Public Server as Asptypelibrary.server
Public session as Asptypelibrary.session
Public Response as Asptypelibrary.response
Public Request as Asptypelibrary.request
Code in CLASS1.CLS:
Private Sub Class_Initialize ()
On Error Resume Next
Set objcontext = GetObjectContext
Set application = Objcontext.item ("Application")
Set Server = Objcontext.item ("server")
Set session = Objcontext.item ("session")
Set Request = Objcontext.item ("request")
Set Response = Objcontext.item ("Response")
End Sub
Private Sub Class_Terminate ()
On Error Resume Next
Set application = Nothing
Set Server = Nothing
Set session = Nothing
Set Request = Nothing
Set Response = Nothing
Set Objcontext = Nothing
End Sub
Public Sub Aspclassinit ()
On Error GoTo ERR
Set conn = Server.CreateObject ("ADODB. Connection ")
Strcon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=" & Server.MapPath ("Article.mdb")
Conn. Open Strcon
Set rs = Server.CreateObject ("ADODB.") Recordset ")
sql = "SELECT * from Article ORDER BY ArticleID Desc"
Rs. Open SQL, Conn, 1, 1
Response.Write "Response.Write "Response.Write "<meta http-equiv=" "Content-type" "content=" "text/html"; charset=gb2312 ">" & vbCrLf
Response.Write "<title> Article Management System-csstudio</title>" & VbCrLf
Response.Write "Response.Write "<body bgcolor=" "#FFFFFF" "topmargin=" "0" ">" & vbCrLf
Response.Write "<table width=" "100%" "border=" "0" "cellpadding=" "2" "cellspacing=" "0" ">" & vbCrLf
Response.Write "<tr>" & VbCrLf
Response.Write "<td width=" "742" "height=" "> Article title </td>" & VbCrLf
Response.Write "<td width=" "> Click </td>" & VbCrLf
Response.Write "<td width=" "145" "> Add Date </td>" & VbCrLf
Response.Write "</tr>" & VbCrLf
Response.Write "</table>" & VbCrLf
While not Rs. EOF and Rows < Rs. PageSize
Response.Write "<table width=" "100%" "border=" "0" "cellspacing=" "0" "cellpadding=" "0" ">" & vbCrLf
Response.Write "<tr>" & VbCrLf
Response.Write "<TD width=" "747" "height=" "," ">☆<a href=" "view.asp?id="
Response.Write rs ("ArticleID")
Response.Write "" > "& vbCrLf