I was just reviewing some old code and found the following (inside foo.asp):
Const ASP_FILENAME = 'foo.asp' ' TODO: Update this to the name of this file (if changed)
The variable is only used for logging errors. (ie. ‘Error in foo.asp – Could not create xxxxx object.’) Is there any way to avoid this?
Thanks!
From the now-defunct Aspfaq.com (thanks to Archive.org):
How do I get the name of the current URL / page?
This one is pretty easy, but there are two parts.
To retrieve the name of the current file, you can use any of these:
To make that path local (for example, to use with FileSystemObject), just apply the server.mappath() method to the result.
To get the entire URL, including the http:// or https:// prefix, you can do this:
To get the page name ONLY, use something like this:
Or, without the IF logic:
Now. If your file is an #INCLUDE within another file, the above scripts will produce the name of the CALLING file (since the included file is first integrated into the calling script, then the ASP within it is all executed in the context of the ‘parent’ file). One way you can work around this is to re-populate a current_filename variable before loading each include file, for example:
(And no, don’t try passing current_filename as a variable to the #INCLUDE directive; see Article #2042.)
Then, in filetoinclude.asp:
Of course, you could just as easily hard-code the filename inside of each include file. But I suppose that solution would somewhat defeat the purpose of retrieving that information at least somewhat dynamically.