获取asp classic中完整路径的虚拟路径
如何获取 ASP classic 中完整路径的虚拟路径。 请注意,完整路径可能位于虚拟目录下,因此简单的
virtPath = Replace(fullPath, Server.MapPath("/"), "")
方法将不起作用。
编辑:为了澄清,一个示例遵循
- 完整的 Windows 文件路径(已知): \\MyServer\MyShare\Web\Site\Logs\Test.txt
- 我的网站有一个虚拟目录 称为日志,指向\\MyServer\MyShare\Web\Site\Logs\。
- 虚拟路径(未知):/Logs/Text.txt
- HTTP 路径(未知,需要): http://Site/Logs/Test.txt
- 代码位于ASP 页面位于主应用程序中,不在任何虚拟目录下。 它位于与相关文件不同的服务器上。
IIS 6.0
如何从完整文件路径中找到虚拟路径?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果有人感兴趣,安东尼·琼斯的回答向我展示了一致地获取应用程序相对根的方法。 因此,如果您有一个位于 http://example.com 的网站,并且在 http://localhost/example,你可以用这个函数找到你的根目录:
然后你可以像这样调用它来获取根路径:
它将返回:
您也可以在不使用斜杠的情况下使用它:
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:
如果我理解了这个问题。
假设
完整路径是当前应用程序或子应用程序中的路径。 它既不是仅限于父应用程序的路径,也不是进入同级应用程序的路径。 所需路径是相对于当前应用程序路径的。
场景 1
之类的路径
诸如“/someApp/someFolder/someSubFolder/file.ext”
应将其解析为:-
“~/someFolder/someSubFolder/file.ext”
(尽管 ~/ 符号不是这是 ASP 经典可以理解的东西)。
场景 2
“/someApp/someSubApp/SomeSubFolder/file.ext”
您仍然想要:-
“~/someFolder/someSubFolder/file.ext”
场景 3
该应用程序是网站的根应用程序:-
“/someFolder/someSubFolder/file.ext”
仍然会变成
“~/someFolder/someSubFolder.file.ext”
解决方案
解决此问题的关键是:-
对于上述内容这将导致一组场景,例如:-
也
将在所有场景都返回
“/LM/W3SVC/33230916”
通过一些数学简化,我们可以得出该函数:-
If I've understood the question.
Assumption
The full path is a path with in the current application or a child application. It is not a path limited to the parent nor a path into a sibling application. The desired path is relative to the current applications path.
Scenario 1
A path such as
"/someApp/someFolder/someSubFolder/file.ext"
should resolve it to:-
"~/someFolder/someSubFolder/file.ext"
(although the ~/ notation isn't something ASP classic understands).
Scenario 2
"/someApp/someSubApp/SomeSubFolder/file.ext"
you still want:-
"~/someFolder/someSubFolder/file.ext"
Scenario 3
The app is the root application of the site:-
"/someFolder/someSubFolder/file.ext"
would still become
"~/someFolder/someSubFolder.file.ext"
Solution
The key to solving this is:-
For the above set of scenarios this will result in something like:-
Also
will in all the scenarios return
"/LM/W3SVC/33230916"
With some mathematical reduction we can arrive at the function:-
尽管可能有更好的方法,但我总是通过创建一个配置变量来实现此目的,在该变量中手动指定不属于虚拟路径的根路径。 这是因为您不知道该站点是否会以 root 身份部署在根 Web 中的文件夹下,或者部署在虚拟目录中。
Although there may be a better way, I always did this by creating a config variable where I manually specify the root path that is not part of the virtual path. This is because you do not know if the site will be deployed as root, under a folder in root web, or in a virtual directory.
好吧,我的答案并不比 OrbMan 的更好...
我已经以这样的方式组织了我的应用程序,每个包含都是相对的...
而不是
\myapp\lib\somefile.asp 我使用 ..\lib\somefile .asp
在其他情况下我只是按照 Orbman 所说的去做......
well, my answer isn't better than OrbMan's...
I have organized my app in such a way that every include is relative...
that is
instead of \myapp\lib\somefile.asp I use ..\lib\somefile.asp
in other cases I just do what Orbman said...
以下是如何通过 ASP 解决 html 中的根相关路径问题,以便您的站点可以移植到不同的托管目录。
这个小片段将生成正确的前缀来设置您的 URL:
您可以在 LINK、IMG、超链接等中使用它,如下所示:
因此,将您的路径编码为相对于根目录(以 / 开头),然后将此片段放在正确的位置在第一个斜杠前面,引号内:
Here's how you solve root-relatie pathing in html via ASP so your site can be portable to different hosting directories.
This little snippet will produce the correct prefix to set your URLs:
You can use this in LINKs, IMGs, hyperlinks, etc as follows:
so, code your paths to be root-relative (starts with a /) and then put this snippet right in front of that first slash, inside the quotes:
服务器的虚拟路径是:
The server's virtual path is: