把ASP用DLL来写的原因:
1、代码保护
ASP的代码是在交付客户的时候是完全被暴露的。相对的保密性没有。市场上出现了很多对Asp加密的产品,但是在起到保护代码的作用的同时,运行速度被降低了,而且也不便于二次开发和管理。而ActiveX DLL完全可以实现Asp能做的所有工作,而且成品是经过编译的DLL文件,这样只把成品交付客户即可,自己的技术得到了很好的保护。
2、运行高效
这一点单凭滔滔不绝的说是没用的!
下面的代码可以证明这个!
先来看看针对用VB来实现的一些必须的代码:
' 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里添加:
Dim i As Long
Dim j As Long
For i = 0 To 10000000
j = j + 2
Next i
mResponse.Write j
End Sub
再在Asp里写:
<%
<%
Response.Write "
" & 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
%>
<%@ Language=VBScript %><%
Dim i,j
Response.Write "
" & 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 %><% Response.Write "
" & Now() & "
" Response.Flush Set obj = server.CreateObject("DSclub.Imgcompose") obj.Count Set obj = Nothing Response.Write "
" & Now() & "
" Response.Flush %><% Response.Write "
" & Now() & "
" Response.Flush Set obj = server.CreateObject("DSclub.Imgcompose") obj.Count Set obj = Nothing Response.Write "
" & Now() & "
" Response.Flush %><% Response.Write "
" & Now() & "
" Response.Flush Set obj = server.CreateObject("DSclub.Imgcompose") obj.Count Set obj = Nothing Response.Write "
" & Now() & "
" Response.Flush %><% Response.Write "
" & Now() & "
" Response.Flush Set obj = server.CreateObject("DSclub.Imgcompose") obj.Count Set obj = Nothing Response.Write "
" & Now() & "
" Response.Flush %><% Response.Write "
" & Now() & "
" Response.Flush Set obj = server.CreateObject("DSclub.Imgcompose") obj.Count Set obj = Nothing Response.Write "
" & Now() & "
" Response.Flush %>