Is there an equivalent to PHP's get_included_files in classic ASP?
Asp – get_included_files in classic ASP
asp-classic
Related Solutions
I know this is an old topic, but I thought I'd add my two cents in case anyone's interested.
I wrote a function that does precisely what you want: includes the given file exactly one no matter how many times it was called.
class ImportFunction
private libraries_
private fso_
private sub CLASS_INITIALIZE
set libraries_ = Server.createObject("Scripting.Dictionary")
set fso_ = Server.createObject("Scripting.FileSystemObject")
end sub
public default property get func (path)
if not libraries_.exists(path) then
on error resume next
with fso_.openTextFile(path)
executeGlobal .readAll
if Err.number <> 0 then
Response.write "Error importing library "
Response.write path & "<br>"
Response.write Err.source & ": " & Err.description
end if
end with
on error goto 0
libraries_.add path, null
end if
end property
end class
dim import: set import = new ImportFunction
Notes:
- This uses a faux function simulated with a default property. If this bothers you, it's easily refactored.
The dictionary must be persistent through all includes, whereas persisting the fso merely avoids reconstructing it. If you don't like the idea of keeping them around after the imports are done, you could modify the class to get syntax like this:
with new Importer .import "foo" .import "bar/baz" end with
Heres a little helper function I use for making HTTP requests in ASP. Its in JScript but you should get the idea at least and some pointers of some nasty gotcha's that we've had to iron out over the years.
<%
/*
Class: HttpRequest
Object encapsulates the process of making an HTTP Request.
Parameters:
url - The gtarget url
data - Any paramaters which are required by the request.
method - Whether to send the request as POST or GET
options - async (true|false): should we send this asyncronously (fire and forget) or should we wait and return the data we get back? Default is false
Returns:
Returns the result of the request in text format.
*/
var HttpRequest = function( url, data, method, options )
{
options = options ? options : { "async" : false };
options[ "async" ] = options["async"] ? true : false;
var text = "";
data = data ? data : "";
method = method ? String( method ).toUpperCase() : "POST";
// Make the request
var objXmlHttp = new ActiveXObject( "MSXML2.ServerXMLHTTP" );
objXmlHttp.setOption( 2, 13056 ); // Ignore all SSL errors
try {
objXmlHttp.open( method, url, options[ "async" ] ); // Method, URL, Async?
}
catch (e)
{
text = "Open operation failed: " + e.description;
}
objXmlHttp.setTimeouts( 30000, 30000, 30000, 30000 ); // Timeouts in ms for parts of communication: resolve, connect, send (per packet), receive (per packet)
try {
if ( method == "POST" ) {
objXmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
}
objXmlHttp.send( data );
if ( options[ "async" ] ) {
return "";
}
text = objXmlHttp.responseText;
} catch(e) {
text = "Send data failed: " + e.description;
}
// Did we get a "200 OK" status?
if ( objXmlHttp.status != 200 )
{
// Non-OK HTTP response
text = "Http Error: " + objXmlHttp.Status + " " + Server.HtmlEncode(objXmlHttp.StatusText) + "\nFailed to grab page data from: " + url;
}
objXmlHttp = null; // Be nice to the server
return text ;
}
%>
If you save that in a file (called httprequest.asp) the you can use it using this code:
<%@ Language="JScript" %>
<!--#include file="httprequest.asp"-->
<%
var url = "http://www.google.co.uk/search";
var data = "q=the+stone+roses"; // Notice you will need to url encode your values, simply pass them in as a name/value string
Response.Write( HttpRequest( url, data, "GET" ) );
%>
One word of warning, if it has an error it will return to you the error message, no way of catching it. It does fine for our needs, if we need a bit more protection then we can create a custom function which can handle the errors a bit better.
Hope that helps.
Best Answer
No, there is not.