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

时间:2021-10-07 05:13:41

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.

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

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?

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

2 个解决方案

#1


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

您也可以从根目录输入绝对路径,例如action =“/ controls / FileUpload.asp”

#2


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

来自Thorarin的一些有用的代码,我刚才在另一篇文章中看到过

Look for ThisPage() Function

寻找ThisPage()函数

#1


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

您也可以从根目录输入绝对路径,例如action =“/ controls / FileUpload.asp”

#2


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

来自Thorarin的一些有用的代码,我刚才在另一篇文章中看到过

Look for ThisPage() Function

寻找ThisPage()函数