How to view ASP source code

Source: Internet
Author: User
How to view ASP source code


The following body:
We all know that ASP is a type of server-side processing program. One of its advantages is to only output data to the client.
Standard HTML stream. Therefore, it can hide details from customers. That is to say, when we are in the browser
After you enter the URL of the ASP program, you can only see the standard HTML file, but not the ASP content. But sometimes,
For example, in an ASP Teaching site, it is necessary for us to display the content of ASP files, or you are willing
Code and people, and the code is displayed through a program.
The following is an ASP program compiled by me, view_code.asp. It provides two submission methods:
Submit the table, that is, you know the physical address of the source file (similar to: C: \ asp_source \ test. asp
Format ). One is to use the get Method for submission (similar to: <a href = "view_code.asp? Code_path =
<% = Server. mappath (request. servervariables ("path_info") %> & cgi_type = asp ">
Click here to view the original code </a> ). In addition, it supports two types of CGI scripts: ASP and PHP.

Code segment:
<%
On Error resume next
'Ignore errors in program execution and handle them at the end of the program.
%>
<%
Function rt_min (num1, num2)
'The subprogram is used to return the minimum number of two numbers that are not equal to zero.
If num1 = 0 and num2 = 0 then
Rt_min =-1
Elseif num1 = 0 then
Rt_min = num2
Elseif num2 = 0 then
Rt_min = num1
Elseif num1 <num2 then
Rt_min = num1
Else
Rt_min = num2
End if
End Function
%>
<%
Function line_check (strline, cgi_type)
'This subroutine is used to check whether the input segment contains special characters such as "<%, %>, <script, or </script
Dim cgi_flag
If cgi_type = "php" then
Cgi_flag = "? "
Else
Cgi_flag = "%"
End if
'Defined cgi_flag is used to represent different identifiers of PHP and ASP.
Line_check = 0
Itemp = 0
IPOs = instr (strline, "<" & cgi_flag)
If rt_min (IPOs, itemp) = IPOs then
Itemp = IPOs
Line_check = 1
End if
IPOs = instr (strline, cgi_flag & "> ")
If rt_min (IPOs, itemp) = IPOs then
Itemp = IPOs
Line_check = 2
End if
IPOs = instr (1, strline, "<" & "script", 1)
If rt_min (IPOs, itemp) = IPOs then
Itemp = IPOs
Line_check = 3
End if
IPOs = instr (1, strline, "<" & "/script", 1)
If rt_min (IPOs, itemp) = IPOs then
Itemp = IPOs
Line_check = 4
End if
End Function
%>
<%
Sub printhtml (strline)
'This subprocess is used to print rows that do not contain the above four special tags
Ispace = Len (strline)-len (ltrim (strline ))
I = 1
While (mid (strline, I, 1) = CHR (9)
Ispace = ispace + 5
I = I + 1
Wend
'Count the number of white spaces
If ispace> 0 then
For I = 1 to ispace
Response. Write ("& nbsp ;")
Next
End if
IPOs = instr (strline, "<")
If IPOs then
Response. Write (left (strline, ipos-1 ))
Response. Write ("& lt ;")
'Use & lt; to replace <, so that the tag in the browser does not explain <>
Strline = right (strline, Len (strline)-IPOS)
Call printhtml (strline)
'Self-called until no <appears
Else
Response. Write (strline)
End if
End sub
%>
<%
Sub printline (strline, iflag, cgi_type)
'This self-process is used for processing according to the return values of line_check.
Dim cgi_flag
If cgi_type = "php" then
Cgi_flag = "? "
Else
Cgi_flag = "%"
End if
Select case iflag
Case 0
Call printhtml (strline)
Case 1
IPOs = instr (strline, "<" & cgi_flag)
Call printhtml (left (strline, ipos-1 ))
Response. Write ("<font color = # ff0000> ")
Response. Write ("& lt;" & cgi_flag)
Strline = right (strline, Len (strline)-ipos-1)
Call printline (strline, line_check (strline, cgi_type), cgi_type)
'Self-called until there are no four special tags
Case 2
IPOs = instr (strline, cgi_flag & "> ")
Call printhtml (left (strline, ipos-1 ))
Response. Write (cgi_flag & "& gt ;")
Response. Write ("</font> ")
Strline = right (strline, Len (strline)-ipos-1)
Call printline (strline, line_check (strline, cgi_type), cgi_type)
Case 3
IPOs = instr (1, strline, "<" & "script", 1)
Call printhtml (left (strline, ipos-1 ))
Response. Write ("<font color = #00ff00> ")
Response. Write ("& lt;" & "script ")
Strline = right (strline, Len (strline)-ipos-6)
Call printline (strline, line_check (strline. cgi_type), cgi_type)
Case 4
IPOs = instr (1, strline, "<" & "/SCRIPT>", 1)
Call printhtml (left (strline, ipos-1 ))
Response. Write ("lt;" & "/script" & "& gt ;")
Response. Write ("</font> ")
Strline = right (strline, Len (strline)-ipos-8)
Call printline (strline, line_check (strline, cgi_type), cgi_type)
Case else
Response. Write ("error ")
End select
End sub
%>
<HTML>
<Head>
<Title> View cgi_code (. asp or. php) </title>
</Head>
<Body>
<Form action = "view_code.asp" method = "Post">
Enter the path: <input type = text name = "code_path">
Select a type: <select name = "cgi_type">
<Option value = "asp"> Asp </option>
<Option value = "php"> php </option>
</SELECT>
<Input type = submit>
</Form>
<HR>
<%
If vartype (request. servervariables ("http_referer") then
'Determine whether the page is submitted by another page application. If the user directly enters the address in the browser
Then, the http_referer environment variable should not be initialized.
If request. servervariables ("request_method") = "Post" then
Code_path = request. Form ("code_path ")
Cgi_type = request. Form ("cgi_type ")
Response. Write ("the following code comes from Table submission:" & "<br> ")
Response. Write ("Path:" & code_path & "<br> ")
Elseif request. servervariables ("request_method") = "get" then
Code_path = request. querystring ("code_path ")
Cgi_type = request. querystring ("cgi_type ")
Response. Write ("the following code comes from" & code_path & "submission:" & "<br> ")
Response. Write ("Path:" & code_path & "<br> ")
End if
'Different prompts are displayed based on the submission method.
Set fileobject = server. Createobject ("scripting. FileSystemObject ")
If fileobject. fileexists (code_path) then
'Check whether the file to be opened exists
Set stream = fileobject. opentextfile (code_path, 1, false, 0)
While not stream. atendofstream
Stroutput = stream. Readline
Call printline (stroutput, line_check (stroutput, cgi_type), cgi_type)
'Send each row of the file to printline for processing.
Response. Write ("<br> ")
Wend
Set stream = nothing
Else
Response. Write ("file cannot be opened" & "<br> ")
End if
End if
%>
</Body>
</Html>
<%
'The following code is a unified error handling segment, which is handled separately based on the error code generated during the program running.
If err. Number <> 0 then
Response. Write ("error" & "<br> ")
Response. Write ("error code:" & err. Number & "<br> ")
Response. Write ("error Description:" & err. description)
End if
%>

Finally, I am giving a test page that references the program.
<HTML>
<Head>
<Title> display the code test page </title>
</Head>
<Body>
<A href = "view_code.asp? Code_path = <% = server. mappath (request. servervariables
("Path_info") %> & cgi_type = asp "> click here to view the source code of this page </a>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.