Recommended: Asp prevents web pages from refreshing code Reduce the server burden, asp prevents web page refresh code SubPreventRefresh() DimRefreshTime, isRefreshRefreshTime=10 prevents refresh time, unit (seconds) isRefresh=1 Whether to use anti-refresh function, 0=No, 1=YesIfisRefresh=1Then If(NotIsEmpty(Session(RefreshTime)))AndRefreshTime0Then IfDateDiff(s,Se
How to use it, add the following code to the page where you need to use file cache.
<!--#includefile=FileCatch.asp-->
<%
SetMyCatch=newCatchFile
MyCatch.Overdue=10 'Modify expiration time set to 10 minutes
ifMyCatch.CatchNow(Rev)then
response.writeMyCatch.CatchData
response.end
endif
setMyCatch=nothing
%>
FileCatch.asp
Copy content to clipboard code:
<%
'This file is used to check in the original file and implement the file Catch of the page
'1. If the file request is POST mode, cancel this function
'2. File requests cannot contain system identification keywords
ClassCatchFile
PublicOverdue,Mark,CFolder,CFile 'Define system parameters
PrivateScriptName,ScriptPath, ServerHost 'Define server/page parameter variables
PublicCatchData' Output Data
PrivateSubClass_Initialize 'Initialize function
'Get server and script data
ScriptName=Request.Servervariables(Script_Name) 'Recognize the virtual address of the current script
ScriptPath=GetScriptPath(false) 'Identify the full GET address of the script
ServerHost=Request.Servervariables(Server_Name) 'Identify the address of the current server
'Initialize system parameters
Overdue=30 'Default 30 minutes expires
Mark=NoCatch 'No Catch request parameter is NoCatch
CFolder=GetCFolder 'Define the default Catch file save directory
CFile=Server.URLEncode(ScriptPath)&.txt 'Convert script path to file path
CatchData=
endSub
PrivateFunctionGetCFolder
dimFSO,CFolder
SetFSO=CreateObject(Scripting.FileSystemObject) 'Set the FSO object
CFolder=Server.MapPath(/)&/FileCatch/
ifnotFSO.FolderExists(CFolder)then
fso.CreateFolder(CFolder)
endif
ifMonth(Now())<10then
CFolder=CFolder&/0&Month(Now())
else
CFolder=CFolder&Month(Now())
endif
ifDay(Now())<10then
CFolder=CFolder&0&Day(Now())
CFolder=CFolder&Day(Now())
endif
CFolder=CFolder&/
ifnotFSO.FolderExists(CFolder)then
fso.CreateFolder(CFolder)
endif
GetCFolder=CFolder
setfso=nothing
EndFunction
PrivateFunctionbytes2BSTR(vIn) 'Convert encoded function
dimStrReturn,ThisCharCode,i,NextCharCode
strReturn=
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR=strReturn
EndFunction
PublicFunctionCatchNow(Rev) 'The user specifies to start processing the Catch operation
ifUCase(request.Servervariables(Request_Method))=POSTthen
'If it is a POST method, file Catch cannot be used
Rev=Request page using POST method, the file Catch function cannot be used
CatchNow=false
else
ifrequest.Querystring(Mark)<>then
'If the specified parameter is not empty, it means that the request cannot use Catch
CatchNow=false
else
CatchNow=GetCatchData(Rev)
endif
endif
EndFunction
PrivateFunctionGetCatchData(Rev) 'Read Catch data
DimFSO, IsBuildCatch
SetFSO=CreateObject(Scripting.FileSystemObject) 'Set the FSO object and access the CatchFile
IfFSO.FileExists(CFolder&CFile)Then
DimFile, LastCatch
SetFile=FSO.GetFile(CFolder&CFile) 'Define the CatchFile file object
LastCatch=CDate(File.DateLastModified)
ifDateDiff(n,LastCatch,Now())>Overduethen
'If the Catch time is exceeded
IsBuildCatch=true
else
IsBuildCatch=false
endif
SetFile=Nothing
else
IsBuildCatch=true
Endif
IfIsBuildCatchthen
GetCatchData=http://www.code-123.com/html/BuildCatch(Rev) 'If you need to create a Catch, create a Catch file and set the Catch data at the same time
else
GetCatchData=http://www.code-123.com/html/ReadCatch(Rev) 'If you don't need to create a Catch, then read the Catch data directly
Endif
SetFSO=nothing
PrivateFunctionGetScriptPath(IsGet) 'Create an address containing all requested data
dimKey,Fir
GetScriptPath=ScriptName
Fir=true
forEachkeyinRequest.QueryString
IfFirthen
GetScriptPath=GetScriptPath&?
Fir=false
else
GetScriptPath=GetScriptPath&&
endif
GetScriptPath=GetScriptPath&Server.URLEncode(Key)&=&Server.URLEncode(Request.QueryString(Key))
Next
ifIsGetthen
IfFirthen
GetScriptPath=GetScriptPath&?
Fir=false
else
GetScriptPath=GetScriptPath&&
endif
GetScriptPath=GetScriptPath&Server.URLEncode(Mark)&=yes
endif
EndFunction
'Create a Catch file
PrivateFunctionBuildCatch(Rev)
DimHTTP, Url, OutCome
SetHTTP=CreateObject(Microsoft.XMLHTTP)
'OnErrorResumeNext
'response.writeServerHost&GetScriptPath(true)
HTTP.Openget, http://&ServerHost&GetScriptPath(true), False
HTTP.Send
ifErr.number=0then
CatchData=http://www.code-123.com/html/bytes2BSTR(HTTP.responseBody)
else
Rev=Error occurred in creation: &Err.Description
BuildCatch=False
Err.clear
endif
CallWriteCatch
setHTTP=nothing
EndFunction
PrivateFunctionReadCatch(Rev)
ReadCatch=IReadCatch(CFolder&CFile,CatchData,Rev)
EndFunction
PrivateSubWriteCatch
DimFSO, TSO
SetFSO=CreateObject(Scripting.FileSystemObject) 'Set the FSO object and access the CatchFile
setTSO=FSO.CreateTextFile(CFolder&CFile,true)
TSO.Write(CatchData)
SetTSO=Nothing
SetFSO=Nothing
EndSub
EndClass
FunctionIReadCatch(File,Data,Rev)
DimFSO, TSO
SetFSO=CreateObject(Scripting.FileSystemObject) 'Set the FSO object and access the CatchFile
'onerrorresumenext
setTSO=FSO.OpenTextFile(File,1,false)
Data=http://www.code-123.com/html/TSO.ReadAll
ifErr.number<>0then
Rev=Error occurred in reading: &Err.Description
ReadCatch=False
Err.clear
else
IReadCatch=True
endif
SetTSO=Nothing
SetFSO=Nothing
EndFunction
%>
Share: Asp calls C# compiled com component example 1 Create a new class library MyTestDLL 2 Right-click the project MyTestDLL-》Attribute-》Generate-》Tick as COM Interoperability Registration 3 Open AssemblyInfo.cs file modification [assembly:ComVisible(true)] 4 Open the command prompt line tool for VisualSutdio2008 Enter DEFINE_GUID. Click NewGUID 5 Code 1. Each class name corresponds to an interface name, interface name