新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:可以查看源代码的ASP程序

可以查看源代码的ASP程序

新客网 XKER.COM 2003-07-03 来源: 收藏本文
<B>ASP Source Code:</B>
<HR>
<%
Dim objFSO, objInFile 'object variables for file access
Dim strIn, strTemp 'string variables for reading and color
processing
Dim I 'standard loop control variable
Dim strASPFileName 'string containing filename of ASP file to view
Dim ProcessString 'flag determining whether or not to output each
line

' We don't start showing code till we find the start script comment
ProcessString = 0

' Get file name from query string
strASPFileName = Request.QueryString("file")

' Conditional limiting use of this file to current directory
If InStr(1, strASPFileName, "\", 1) Then strASPFileName = ""
If InStr(1, strASPFileName, "/", 1) Then strASPFileName = ""

' Set the default so it shows itself if nothing or an invalid
' path is passed in. Delete the following line to just display
' a message.
If strASPFileName = "" Then strASPFileName = "source.asp"

If strASPFileName <> "" Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile("D:\Webs\asp101
\www\samples\" & strASPFileName)

Response.Write "<PRE>" & vbCRLF
' Loop Through Real File and Output Results to Browser
Do While Not objInFile.AtEndOfStream
strIn = Server.HTMLEncode(objInFile.ReadLine)
' Check for start script comment
If InStr(1, strIn, "&lt;!-- BEGIN SCRIPT --&gt;",
1) Then
ProcessString = 1
strIn = Server.HTMLEncode
(objInFile.ReadLine)
End If
' Check for end script comment
If InStr(1, strIn, "&lt;!-- END SCRIPT --&gt;", 1)
Then ProcessString = 0
' If we're on a line to be processed then do so
If ProcessString = 1 Then
strTemp = ""
' Loop through line
For I = 1 to Len(strIn)
' First look for script openers
to start red
If InStr(I, strIn, "&lt;%", 1) =
I Then
strTemp = strTemp
& "<FONT COLOR=#FF0000>" & Mid(strIn, I, 1)
Else
' If no script openers
look for closers to end red
If InStr(I, strIn, "%
&gt;", 1) = I Then
strTemp =
strTemp & "%&gt;</FONT>"
I = I + 4
Else
' If neither
just copy to strTemp as is
strTemp =
strTemp & Mid(strIn, I, 1)
End If
End If
Next
' Output out processed line
Response.Write strTemp & vbCRLF
End If
Loop
Response.Write "</PRE>" & vbCRLF

' Close file and free variables
objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
Else
' If they entered no filename or one with a / or \ ... deny
access
Response.Write "Sorry, but you do not have access to view
files outside the current directory."
End If
%>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐