把ASP用DLL來寫的原因:
1、代碼保護
ASP的代碼是在交付客戶的時候是完全被暴露的。相對的保密性沒有。市場上出現了很多對Asp加密的產品,但是在起到保護代碼的作用的同時,運行速度被降低了,而且也不便於二次開發和管理。而ActiveX DLL完全可以實現Asp能做的所有工作,而且成品是經過編譯的DLL檔案,這樣只把成品交付客戶即可,自己的技術得到了很好的保護。
2、運行高效
這一點單憑滔滔不絕的說是沒用的!
下面的代碼可以證明這個!
先來看看針對用VB來實現的一些必須的代碼:
' ------------ 用ActiveX DLL來寫ASP --------------------
' Author:任兀
' Nick Name:DSclub
' CSDN: dsclub(兀兒)
' WebLog:www.cnblogs.com/dsclub
' QQ:9967030
' ||||||||||||||||||||| 說 明 |||||||||||||||||||||||
'
' 必須要執行的工作:
' 1、引用 MicroSoft Active Server Page Object Library組件
' 2、添加 OnStartPage OnEndPage 事件
' 3、OnStartPage事件負責接收 ScriptingContext 對象
' 該對象提供ASP頁面環境
'
'
'||||||||||||||||||||||||||||||||||||||||||||||||||||||
Option Explicit
' ===========================================================
' ------------ 必須的Asp對象 ----------------
Private mContext As ScriptingContext
Private mApplication As Application
Private mResponse As Response
Private mRequest As Request
Private mSession As Session
Private mServer As Server
' ------------------------------------------
' 接收ScriptingContext對象
' 初始化各個ASP對象
Public Sub OnStartPage(PassedScriptContext As ScriptingContext)
' Asp運行環境對象
Set mContext = PassedScriptContext
' Asp 五大對象
Set mApplication = mContext.Application
Set mRequest = mContext.Request
Set mResponse = mContext.Response
Set mServer = mContext.Server
Set mSession = mContext.Session
End Sub
' 釋放內部對象
Public Sub OnEndPage()
Set mApplication = Nothing
Set mRequest = Nothing
Set mResponse = Nothing
Set mServer = Nothing
Set mSession = Nothing
Set mContext = Nothing
End Sub
' ===========================================================
好了,我認為注釋寫的還算可以啦……
直接證明速度上的優勢啦,KKK~~~~~~~~~~
在VB裡添加:Public Sub Count()
Dim i As Long
Dim j As Long
For i = 0 To 10000000
j = j + 2
Next i
mResponse.Write j
End Sub
再在Asp裡寫:
<%
" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>Response.Write "<br/>" & Now() & "<br/>"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "<br/>" & Now() & "<br/>"
Response.Flush
%>
同樣的代碼功能用純Asp來實現一下:
<%@ Language=VBScript %>
<%
Dim i,j
Response.Write "<br>" & Now() & "<br>"
Response.Flush
For i=0 to 10000000
j = j+2
next
Response.Write j
Response.Write "<br>" & Now() & "<br>"
Response.Flush
%>
" & Now() & "
"
Response.Flush
For i=0 to 10000000
j = j+2
next
Response.Write j
Response.Write "
" & Now() & "
"
Response.Flush
%>
分別運行兩個頁面看結果:
靠,都不想說了
DLL的那個頁面結果:
2004-7-10 15:41:48
20000002
2004-7-10 15:41:48
純Asp的那個頁面結果:
2004-7-10 15:41:38
20000002
2004-7-10 15:41:42
我的機器是
P42.8c 512M的
OS:windos XP
竟然差了這麼多!!!
" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>" & Now() & "
"
Response.Flush
Set obj = server.CreateObject("DSclub.Imgcompose")
obj.Count
Set obj = Nothing
Response.Write "
" & Now() & "
"
Response.Flush
%>