ASP Kaynak Kodunu Görüntüleme
Bu dersimizde bir örnek ile sizlere, sayfa kaynak kodunun görüntülenmesini
anlatmaya çalışacağım. Burada yaptığımız tek işlem, hali hazırda yazılı olan
kodların ziyaretçiler tarafından da görüntülenebilmesini sağlamak.
Neden buna ihtiyaç duyayım ki diyenler vardır mutlaka. Size 2 küçük düşünce
ile anlatayım;
EASP ilişkili bir sayfanız varsa, bir sayfanın herhangi bir bölümünün kaynak
kodunu görüntülemek için kolay bir yoldur. Ayrıca ASP dosyasını değiştirdiğinizde
kaynak kodu değiştirmenize gerek kalmayacağından size yarar sağlar.Tabi eğer
açık kodlu bir siteniz varsa.
Eğer buraya kadar anlaşabildiysek buyrun örnek kodları inceleyelim;
<B>ASP Kaynak Kodu:</B>
<HR>
<%
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
strFileName = Request.QueryString("file")
' Dosya kullaniminin kosullu sinirlandirmasi
if InStr(1, strFileName, "\", 1) then strFileName=""
if InStr(1, strFileName, "/", 1) then strFileName=""
if strFileName <> "" then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(Server.MapPath(strFileName))
response.write "<PRE>" & vbCRLF
' Gerçek Dosya ile Çikti arasindaki browser döngüsü
Do While Not objInFile.AtendOfStream
strIn = Server.HTMLEncode(objInFile.ReadLine)
if InStr(1, strIn, "<!-- BEGIN SCRIPT -->", 1) then
ProcessString = 1
strIn = Server.HTMLEncode(objInFile.ReadLine)
end if
if InStr(1, strIn, "<!-- END SCRIPT -->", 1) then ProcessString
= 0
if ProcessString = 1 then
strTemp = ""
For I = 1 to Len(strIn)
bCharWritten = False
if InStr(I, strIn, "<%", 1) = I then
strTemp = strTemp & "<FONT COLOR=#0000FF>"
bInsideScript = True
else
if InStr(I, strIn, "%>", 1) = I then
strTemp = strTemp & "%></FONT>"
bCharWritten = True
' ie. Len("%>") - 1 = 4
I = I + 4
bInsideScript = False
end if
end if
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)
= 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 strTemp & vbCRLF
end if
loop
response.write "</PRE>" & vbCRLF
objInFile.Close
Set objInFile = Nothing
Set objFSO = Nothing
else
strFileName = "index.asp"
end if
%>
Kolay Gelsin...
AsP ÖrNeKlErİ