How can I get the virtual path for a full path in ASP classic. Note that the full path may be under a virtual directory and therefore the simplistic
virtPath = Replace(fullPath, Server.MapPath("/"), "")
method will not work.
Edit: To clarify, an example follows
- Full Windows File Path (known):
\\MyServer\MyShare\Web\Site\Logs\Test.txt - My Website has a Virtual directory
called Logs that Points to \\MyServer\MyShare\Web\Site\Logs\. - Virtual Path (unknown): /Logs/Text.txt
- Http path (unknown, needed):
http://Site/Logs/Test.txt - The code is in a asp page in the main app, not under any virtual directories. It is located on a separate server from the file in question.
-
IIS 6.0
How do I find the virtual path from the full file path?
Best Answer
In case anyone's interested, Anthony Jones' answer showed me the way to getting the application's relative root consistently. So if you have a site at http://example.com and a local development equivalent at http://localhost/example, you can find your root with this function:
You can then call it like this to get the root path:
Which will return:
You can also use it without the slash: