使用 vbscript/classic asp 确定资源的绝对 url

发布于 2024-07-26 11:32:21 字数 1280 浏览 6 评论 0原文

我为一个用经典 asp 编写的站点创建了一个伪用户控件。 该控件只是一个位于父页面 iframe 内的 asp 页面(具有完整的 HTML 标头和正文)。 重点是创建一个类似 AJAX 的接口来异步上传文件(父页面包含一个大表单,我不想同时上传文件并提交表单的其余部分)。
问题是,我在 iframe 页面/用户控件中使用相对 url 时遇到了很多问题。 根据 iframe 是哪个页面的子页面,相对 url 基本位置似乎会根据特定页面所在的目录而变化。

示例: www.website.com/directory1/application1.asp

...
<form>
    <input>
    ...
    <iframe src="../controls/FileUpload.asp"/>
    ...
</form>
...

www.website.com/directory1/directory2/application2.asp

...
<form>
    <input>
    ...
    <iframe src="../../controls/FileUpload.asp"/>
    ...
</form>
...

www.website.com/controls/FileUpload.asp

...
<form method="post" enctype="multipart/form-data" action="FileUpload.asp"><!--problem here-->
    <input type="file">
    <input type="submit"/>
</form>

iframe src 路径工作正常(注意埋藏更深的目录)有一个额外的双点)。 但在 FileUpload.asp 页面的代码中,相对 URL 的工作方式不一致。 如果您只是按原样加载页面,而不是在另一个页面的 iframe 中加载,那么表单标记的 action 属性中的 URL 就可以工作。 您可以将其更改为“../controls/FileUpload.asp”,它将在第一个应用程序页面上运行,但您必须添加另一个“../”才能在第二个应用程序页面上运行。
我想知道是否有一种方法可以使用 vbscript 来查找某个文件的绝对 URL。 我确实使用了一个包含文件,我可以将其硬编码到其中,但如果可能的话,我宁愿不这样做。 还有其他想法吗?

I've created a pseudo user control for a site written in classic asp. The control is simply an asp page (with full HTML headers and body) that resides within an iframe in the parent page. The point was to create an AJAX-like interface for uploading files asynchronously (the parent page contains a large form and I didn't want to have to upload the files and submit the rest of the form at the same time).
The problem is, I'm running into a lot of issues with relative urls being used in the iframe page/user control. Depending on what page the iframe is a child of, the relative url base location seems to change according to the directory that particular page is in.

Example:
www.website.com/directory1/application1.asp

...
<form>
    <input>
    ...
    <iframe src="../controls/FileUpload.asp"/>
    ...
</form>
...

www.website.com/directory1/directory2/application2.asp

...
<form>
    <input>
    ...
    <iframe src="../../controls/FileUpload.asp"/>
    ...
</form>
...

www.website.com/controls/FileUpload.asp

...
<form method="post" enctype="multipart/form-data" action="FileUpload.asp"><!--problem here-->
    <input type="file">
    <input type="submit"/>
</form>

The iframe src paths work correctly (notice the one that's buried a directory deeper has an extra double dot). But in the code for the FileUpload.asp page, relative URLs don't work consistently. The URL I have in the action attribute for the form tag works if you simply load the page as-is, not in an iframe of another page. You can change it to "../controls/FileUpload.asp" and it will work on the first application page, but you have to add another "../" for it to work on the second application page.
I was wondering if maybe there's a way with vbscript to find the absolute URL to a certain file. I do use an include file into which I could hard-code this, but I'd rather not if that's possible. Any other ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小女人ら 2024-08-02 11:32:21

您也可以只输入从根开始的绝对路径,例如
动作=“/controls/FileUpload.asp”

You could also just put in an absolute path from the root such as
action="/controls/FileUpload.asp"

赠我空喜 2024-08-02 11:32:21

我不确定您是否正在寻找来自

<%
Response.Write Server.MapPath("./foo.txt")
%>

一些有用的代码 a href="https://stackoverflow.com/users/64767/thorarin">索拉林
我刚刚在不同的帖子中看到

寻找 ThisPage() 函数

I'm not sure if you are perhaps looking for

<%
Response.Write Server.MapPath("./foo.txt")
%>

Some usefull code from Thorarin
that I just saw in a different post

Look for ThisPage() Function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文