Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the source file of an ASP page.

Status
Not open for further replies.

jslmvl

Vendor
Jan 26, 2008
268
GB
In user side, in IE, we can get an ASP page's source file by View Source.
My question is: In server side, using ASP, how to get the source file?

Thank you in advance.
 
user side - no. ASP is a server language and it's output is html or something which the users browser sees.

If you have access to the ASP code(stored on that server) then you can double click the file and see the code. And no, there isn't a way to get the code through a web browser or a different server.
 
I think the question is how to use vbSCript to grab the HTML that is generated by the ASP server. Should be able to use XMLHTTP to do this. Something like:

Dim xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", " False
xml.Send
Response.Write xml.responseText
Set xml = Nothing
 
Thaks a lot for above two helps.

Spork52,
That is very interested....but can I write xml.responseText into a text file?
 
OK, perhaps something wrong in " After change something in that file, Spork52's code seems working now.

I then try to write xml.responseText into a text file:
<%
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", " False
xml.Send
Response.Write xml.responseText

Dim fso, path, text
Set fso = Server.CreateObject("Scripting.FileSystemObject")
path= Server.MapPath("myfile.txt")
Set text = fso_OpenTextFile(path, 2)
text.Write xml.responseText

text.Close()
Set text = Nothing
Set fso =Nothing
Set xml = Nothing
%>

I put the above code in a asp file and save it under .../ However, my untivirus thinks it is a virus!!!
 
Writing the info to a text file is possible. I posted how to do that here:


The example I gave gets data from a DB and writes to a CSV file line by line. What you want to do is simpler. Just get rid of the database code and the looping.

As far as crashing your server ... hmm. You didn't put the xml code in the file that you are retrieving, did you? That might cause an endless loop.
 
Our posts overlapped. Glad you got the crashing fixed. As far as writing to the server, you have to have write permissions in the folder you are writing to. I have no clue what the antivirus program is doing. BTW, what are you trying to accomplish by writing the HTML to the server?
 
Thank you.

>what are you trying to accomplish
I have found it needs long time to display an asp onto the IE. This asp need to do a lot database things but the database is updated only occasionally.
I want to save the result of the asp into a html file whenever the dababase is updated. By this way, I can display the html and hope it will be much faster.

I will go and get your code and have a try. However, I am wondering my untivirus will ask me to delete that if your code includes XMLHTTP and FileSystemObject like my code above.
 
OK, I have just get your code and found it is similar to my code above.
Will you dare enough to save my code as a .html file and save the file to your folder? See if any vurus alert :)
 
>Set xml = Server.CreateObject("Microsoft.XMLHTTP")
It is not thread-safe. It cannot be used to request page of the same site. Change it to this.
[tt]Set xml = Server.CreateObject("Msxml2.ServerXMLHTTP")[/tt]
Then, depending on your purpose, you might have to escape some of the characters of responsetext such as angle bracket.
 
tsuji,

Thank you for your help. I am going to try ("Msxml2.ServerXMLHTTP")

Before that, can you tell me how to do the special character escape?

What I need is to write the result into a .html file by the fso something like
fsoText.Write xml.responseText
Do I need to do the character escape for xml.response.text?
 
I don't think using Msxml2.ServerXMLHTTP will make any difference. See this page from Microsoft:
Especially this part (which I don't quite understand, but which addresses the issue):

Code:
NOTE: The two ASPs should be in different virtual folders due to threading issues.

If pooling is set to Low or Medium (this is the default for Microsoft Windows 2000), you should POST to an ASP in a different virtual folder. If the ASP is in the same virtual folder, the ASP stops responding (hangs). After you close the browser, that ASP and other ASPs continue to hang because the request stays queued even though you close the browser. You must restart IIS or restart the computer.

If you change the pooling to High, you can run the code to the remote ASP again because you are using a new thread.

Does that just mean to put the sending and receiving files in different folders?
 
Or, is it talking about two separate installations of ASP? I guess you could just change the pooling setting, but I'm sure there are all kinds of performance issues involved with that.
 
I think I shouldn't continue this job.....I am not good enough. Although I am testing in my computer, eventually I need it to be run in a remove server which I got no control. Think about the difficulties: virus alert and crashing whole server!!
 
Too bad. There must be some other way of caching ASP output. Probably some server software that can do it.
 
>I don't think using Msxml2.ServerXMLHTTP will make any difference.
For many cases, maybe; but for this case, the difference is more real than imaginary.
 
In my case, there is no virus alert anymore by using Msxml2.ServerXMLHTTP.

However, when the asp file include two-byte characters, xml.responseText cannot be written into a text file.
 
>However, when the asp file include two-byte characters, xml.responseText cannot be written into a text file.
You should test it out using response.binarywrite to send the responsebody to see if things are in order.
[tt] response.binarywrite xml.responsebody[/tt]
The browser has then to set to the proper encoding such as utf-16 big or little endian or whatever other proper.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top