频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

[ASP-Last-Code]显示ASP页面的代码

来源: 作者: 出处:巧巧读书 2006-10-17 进入讨论组
访问地址 http://www.qqread.com/asp/2006/10/n221294.html
<%
'*************************************************************
'在支持FSO的情况下,可以显示本站内的所有ASP页面的代码
'适用于代码演示时在效果页面上直接显示该页面的代码而不用再对代码制作专门的页面
'使用方法:ViewSource.ASP?file=要显示的文件名
'如:ViewSource.ASP?file=x.ASP
'modify By : Babyt
'*************************************************************
%>
<B Style="font-size:12px;font-family:Courier New">HTML/ASP Source Code:</B>
<HR SIZE=1>
<%
Dim objFSO, objInFile
Dim strIn, strTemp
Dim I, J
Dim strFileName
Dim ProcessString
Dim bCharWritten
Dim bInsideScript
Dim bInsideString
Dim iInsideComment

ProcessString = 0
bCharWritten = False
bInsideScript = False
bInsideString = False
iInsideComment = 0
linecount = 1

strFileName = Request.QueryString("file")

'为了保护你的其他页面,进行简单保护,只允许访问当前目录下的文件
'你可以根据实际需要增加更过规则
If InStr(1, strFileName, "\", 1) Then strFileName=""
If InStr(1, strFileName, "/", 1) Then strFileName=""

If strFileName <> "" Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
'判断文件是否存在
If objFSO.FileExists(Server.MapPath(strFileName))=False Then
Response.Write "文件不存在"
Response.End
End If
'打开文件
Set objInFile = objFSO.OpenTextFile(Server.MapPath(strFileName))
Response.Write "<PRE Style='font-size:12px;font-family:Courier New'>" & vbCRLF
'按行读取文本流
Do While Not objInFile.AtEndOfStream
'进行编码
strIn = Server.HTMLEncode(objInFile.ReadLine)
strTemp = ""
'判断起始 < %
'对整个脚本快加亮,n默认蓝色
For I = 1 to Len(strIn)
bCharWritten = False
If InStr(I, strIn, "&lt;%", 1) = I Then
strTemp = strTemp & "<FONT COLOR=#0000EE>"
bInsideScript = True
Else
'判断结束标志位 % >
If InStr(I, strIn, "%&gt;", 1) = I Then
strTemp = strTemp & "%&gt;</FONT>"
bCharWritten = True
' so we dont get the trailing end of this tag again!
' ie. Len("%&gt;") - 1 = 4
I = I + 4
bInsideScript = False
End If
End If
' Toggle Inside String if needed!
If bInsideScript And iInsideComment = 0 And InStr(I, strIn, "&quot;", 1) = I Then bInsideString = Not bInsideString
'判断可能的注释,主要是为了改变其颜色(默认绿色)
If bInsideScript And Not bInsideString And (InStr(I, strIn, "'", 1) OR InStr(I, strIn, "//", 1)) = I Then
strTemp = strTemp & "<FONT COLOR=#009900>"
iInsideComment = iInsideComment + 1
End If
' 结束注释文字处理
If iInsideComment > 0 And I = Len(strIN) Then
strTemp = strTemp & Mid(strIn, I, 1)
For J = 1 to iInsideComment
strTemp = strTemp & "</FONT>"
Next 'J
bCharWritten = True
iInsideComment = 0
End If
If bCharWritten = False Then
strTemp = strTemp & Mid(strIn, I, 1)
End If
Next
'此句写行号,可以把行号去掉
Response.Write "<FONT COLOR=#666666>" & linecount & "</font>&nbsp;&nbsp;" & strTemp & vbCRLF
linecount = linecount + 1
Loop
Response.Write "</PRE>" & vbCRLF

objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
End If
%>进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章