显示ASP页面源码的代码
作者:Babyt 时间:2008-10-12 13:05:00
在支持FSO的情况下,可以显示本站内的所有ASP页面的代码
适用于代码演示时在效果页面上直接显示该页面的代码而不用再对代码制作专门的页面
使用方法:ViewSource.asp?file=要显示的文件名
如:ViewSource.asp?file=x.asp
<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, "<%", 1) = I Then
strTemp = strTemp & "<FONT COLOR=#0000EE>"
bInsideScript = True
Else
'判断结束标志位 % >
If InStr(I, strIn, "%>", 1) = I Then
strTemp = strTemp & "%></FONT>"
bCharWritten = True
' so we dont get the trailing end of this tag again!
' ie. Len("%>") - 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, """, 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> " & strTemp & vbCRLF
linecount = linecount + 1
Loop
Response.Write "</PRE>" & vbCRLF
objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
End If
%>
标签:fso,源码,asp
0
投稿
猜你喜欢
基于Python利用Pygame实现翻转图像
2021-05-20 00:05:08
Sql 语句学习指南第1/2页
2024-01-25 07:13:01
python多进程基础详解
2021-07-14 10:06:52
mysql 一次向表中插入多条数据实例讲解
2024-01-14 06:34:48
MySql范围查找时索引不生效问题的原因分析
2024-01-12 14:42:33
Django ORM F对象和Q对象查询
2023-10-23 15:33:04
Python实现微信好友数据爬取及分析
2021-09-30 04:51:55
用Python编写简单的定时器的方法
2022-03-15 07:20:32
Python3 字典dictionary入门基础附实例
2023-03-08 18:57:49
实例解析Python中的__new__特殊方法
2023-01-09 22:26:19
SQL SERVER2012中新增函数之字符串函数CONCAT详解
2024-01-23 18:15:23
ThinkPHP5集成JS-SDK实现微信自定义分享功能
2023-06-10 13:59:47
MySQL在右表数据不唯一的情况下使用left join的方法
2024-01-18 22:42:02
Selenium常见八大定位法总结
2022-07-05 02:16:21
微信小程序webview组件交互,内联h5页面并网页实现微信支付实现解析
2023-07-02 05:30:09
Python实现将不规范的英文名字首字母大写
2021-05-21 08:40:46
Python练习之操作MySQL数据库
2024-01-20 12:29:22
PHP一文带你搞懂游戏中的抽奖算法
2024-06-05 09:38:21
Pycharm学习教程(1) 定制外观
2021-08-01 05:18:11
asp如何实现无组件上传二进制文件?
2010-06-03 10:09:00