改進版本(V2.0):
<%
' **** Dynamic ASP include v.2.0
function fixInclude(content)
out=""
if instr(content,"#include ")>0 then
response.write "Error: include directive not permitted!"
response.end
end if
content=replace(content,"<"&"%=","<"&"%response.write ")
pos1=instr(content,"<%")
pos2=instr(content,"%"& ">")
if pos1>0 then
before= mid(content,1,pos1-1)
before=replace(before,"""","""""")
before=replace(before,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""")
before=vbcrlf & "response.write """ & before & """" &vbcrlf
middle= mid(content,pos1+2,(pos2-pos1-2))
after=mid(content,pos2+2,len(content))
out=before & middle & fixInclude(after)
else
content=replace(content,"""","""""")
content=replace(content,vbcrlf,""""&vbcrlf&"response.write vbcrlf&""")
out=vbcrlf & "response.write """ & content &""""
end if
fixInclude=out
end function
Function getMappedFileAsString(byVal strFilename)
Dim fso,td
Set fso = Server.CreateObject("Scripting.FilesystemObject")
Set ts = fso.OpenTextFile(Server.MapPath(strFilename), 1)
getMappedFileAsString = ts.ReadAll
ts.close
Set ts = nothing
Set fso = Nothing
End Function
execute (fixInclude(getMappedFileAsString("included.asp")))
%>
來源
2011-07-19 17:25:20
tfi
[4guysfromrolla(http://www.4guysfromrolla.com/)有着相當不錯的[文章](HTTP:// WWW。 4guysfromrolla.com/ASPScripts/PrintPage.asp?REF=%2Fwebtech%2F022504-1.shtml)。 – 2009-04-28 17:10:09
您應該查看[ExecuteGlobal](http://msdn.microsoft.com/en-us/library/342311f1(VS.85).aspx)。請參見[使用ExecuteGlobal來包含VBScript代碼]中的示例3(http://www.gwmicro.com/Support/Knowledge_Base/?kbnumber=GWKB2035) – loraderon 2009-04-21 13:46:32
儘管如此,Server.Execute在編寫動態模板系統時對我很好,因爲模板文件本身從未被期望添加新的功能/本身/。我確實必須將一個對象粘貼到Session var中才能將其傳遞給「included」文件。所以......長話短說,即使你從未得到過你想要的東西,你的問題對我也很有幫助。 :-) – 2017-10-03 18:22:20