Iv. development and use of ASP components:
1. Features of the component?
L Advantages:
n easy to invoke, save code
N High Security
n supports transaction processing, multi-component syndication
N Run Fast
n Upgrade, modify components without modifying the page, so scalability is good
L Disadvantages:
n Development and debugging difficulties
2. How to use VB development?
⑴. Open Vb>>new Project>>activex DLL
⑵. Modify project name to course
⑶. Modify the name of the class module conn_db
⑷. Project>> References, referencing the COM + Service Type Library and Microsoft Active Server Pages Object Library.
⑸. Modify the class code as follows:
' Establish a database connection and output database fields
Dim Response as Response
Dim Request as Request
Dim Server as Server
Dim Application as Application
Dim Session as session
Private Sub Class_Initialize ()
Dim Objcontext as ObjectContext
Set objcontext = GetObjectContext ()
Set Response = objcontext ("Response")
Set Request = objcontext ("request")
Set Server = objcontext ("server")
Set application = objcontext ("Application")
Set session = Objcontext ("session")
End Sub
Sub conn_db ()
Set conn = CreateObject ("Adodb.connection")
Conn.Open "Course_dsn", "Course_user", "Course_password"
Set rs = CreateObject ("Adodb.recordset")
Rs.Open "SELECT * from User_info", Conn, 1, 1
If rs.recordcount > 0 Then
For i = 1 to Rs.recordcount
Response.Write "<br>" & RS ("user_name") & "<br>"
If Rs. EOF Then Exit for
Rs.movenext
Next
End If
Rs. Close
Set rs = Nothing
Conn. Close
Set conn = Nothing
End Sub
⑹. Add a new class Cutstr
⑺. Modify the class code as follows:
' Intercept string
Function cutstr (str, length)
If Len (str) > Length Then
Cutstr = Left (str, length) & "..."
Else
CUTSTR = str
End If
End Function
⑻. File>>save
⑼. File>>make Course.dll
3. Registration components: MTS and Regsvr32.exe
There are two ways to register components: MTS and the use of Regsvr32.exe. MTS is worth recommending because it has the following advantages:
n Dynamic offload balancing to improve the upgrade of components and component-based applications.
n contains the ability to advertise and submit events and queue components, making it easier to combine with multiple components.
For a component to have an MTS feature, you must make minor changes to the component. When you develop under NT and 98, you must refer to the Microsoft Transaction Server type library in your project, developed under Windows 2000, and you must reference the COM + Service type library.
⑴. REGSVR32 registration:
Regsvr32.exe is an executable file under System32 that reads the component information into the registry so that ASP can invoke it.
Use the command line to enter the directory where the component DLL file is located, and execute "regsvr32 dll_file_name".
When you run Regedit, the course.conn_db and course.cutstr items are found under HKEY_CLASSES_ROOT, indicating that the component was registered successfully.
⑵. Register with MTS:
①. Start >> program >> management tools >> Component Services
②. Expand the directory to the following states:
③. Follow the wizard and next, until the following dialog box, click "Create an Empty Application":
④. In the next dialog box, name the Application "course", and the other defaults until complete
⑤. Expand the course application, right-click, and create a new component
⑥. Follow the prompts, continue, and select "Import registered Components" when the following dialog box appears
⑦. Select the component we developed, and the next step is to complete
⑧. At this point, you can see that there are two more components in the course application:
4. Calling Components in ASP
Asp_use_com.asp
<%
' ASP calls COM components
Set Cutstr_obj=server.createobject ("Course.cutstr")
Response.Write Cutstr_obj.cutstr ("Abcdefghijk", 3) & "<br>"
Set cutstr_obj=nothing
Set Conn_obj=server.createobject ("course.conn_db")
conn_obj.conn_db ()
Set conn_obj=nothing
%>
Effect:
Abc...
Ahyi
Tuth
Description the call succeeded.
5. Uninstalling components
⑴. Using regsvr32 registered components, use the-u switch to uninstall:
Note: First enter the directory where the component DLL resides, then uninstall using "Regsvr32–u Dll_file_name", and restart IIS after uninstalling.
⑵. Components registered with MTS, first remove the corresponding application in Component Services, and then perform step ⑴ to completely uninstall the component.
6. DLL component storage location and permission settings
⑴. All we need to do is copy the compiled DLL file and the other files don't have to be processed.
⑵. To put a DLL outside of a Web site, such as the System32 directory, to prevent being downloaded
⑶. DLL's file rights are set to system read, Internet users traverse folders/Run files
⑷. DLL removes all permissions in IIS, such as read, script voluntary access, etc.
The above processing ensures that the DLL files are secure.
7. Other
How can I use ASP's objects in a component to easily migrate ASP code into COM components?
Five, IIS optimization configuration
1. Web site Tabs: IP, port, virtual host, connection, log
2. ISAPI filters: Adding PHP and JSP support
3. Home Directory Configuration tab: I is permissions settings (combined with file rights), execution permissions, application protection, mappings, buffering, parent paths, error messages
4. Other tabs: Custom errors, HTTP headers, directory security, document
5. The advantages and disadvantages of file compression
Vi. Other
1. Send mail (jmail;ms SMTP)
Send e-mail using Microsoft SMTP
⑴. Install the Microsoft SMTP Service
⑵. Setting up the Microsoft SMTP Service
⑶. Code section:
Mail_smtp.asp
<%
Sub SendMail (Fromwho,towho,subject,body)
Dim mymail
Set mymail = Server.CreateObject ("Cdonts.newmail")
Mymail.from = fromwho
Mymail.to = towho
Mymail.subject = Subject
Mymail.body = Body
Mymail.send
Set mymail = Nothing
End Sub
%>