Wednesday, August 15, 2007

Get the Source of an .asp Document

Viewing the source of an asp document from a web browser allows only for the viewing of the output html text. Any text written in between <% %> is not outputted to the browser unless a write command is inserted. This is good for security, but bad for developers who made need to look at the code and do not have a local copy. The following script will read any text file (.asp, .html, .inc are all examples) and output it to the browser by changing the page_to_read value to a document relative to the position of the .asp code your using to read it (Example to read the index.asp document in the parent directory it should read page_to_read="../index.asp")


-------------------------------
' Target page to be read
page_to_read="view_source.asp"

' Create a server object
set fso = createobject("scripting.filesystemobject")

' Set the path to document to be read
set act = fso.opentextfile(server.mappath(page_to_read))

' Read the contents of the document to the
' read_text variable

read_text = act.readall

' Close the server object
act.close

' Write the inputted text out to the browser
' and html encode it to display as source
' enclosed in
 tags to display as read
response.write "
" & server.htmlencode(read_text) & "
"

------------------------------------

No comments: