标题: 显示ASP页面的代码
问天
元帅
Rank: 1


元帅勋章 终身成就勋章
UID 11493
精华 187
积分 34221
帖子 33355
威望 91
金币 13148
热心 2619
阅读权限 100
注册 2006-4-7
状态 离线
显示ASP页面的代码

<%
'*************************************************************
'在支持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'>" &;amp; 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, "&;amp;lt;%", 1) = I Then
    strTemp = strTemp &;amp; "<FONT COLOR=#0000EE>"
    bInsideScript = True
   Else
    '判断结束标志位 % >
    If InStr(I, strIn, "%&;amp;gt;", 1) = I Then
     strTemp = strTemp &;amp; "%&;amp;gt;</FONT>"
     bCharWritten = True
     ' so we dont get the trailing end of this tag again!
     ' ie. Len("%&;amp;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, "&;amp;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 &;amp; "<FONT COLOR=#009900>"
    iInsideComment = iInsideComment   1
   End If
   ' 结束注释文字处理
   If iInsideComment > 0 And I = Len(strIN) Then
     strTemp = strTemp &;amp; Mid(strIn, I, 1)
     For J = 1 to iInsideComment
      strTemp = strTemp &;amp; "</FONT>"
     Next 'J
     bCharWritten = True
     iInsideComment = 0
   End If
   If bCharWritten = False Then
    strTemp = strTemp &;amp; Mid(strIn, I, 1)  
   End If
  Next
  '此句写行号,可以把行号去掉
  Response.Write "<FONT COLOR=#666666>" &;amp; linecount &;amp; "</font>&;amp;nbsp;&;amp;nbsp;" &;amp; strTemp &;amp; vbCRLF
  linecount = linecount   1
Loop
Response.Write "</PRE>" &;amp; vbCRLF   
objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
End If
%>

网友 问天 签名 - 网友社区 请您回个帖。谢谢
PR查询 免费域名 免费空间
顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-11-23 17:17
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP