views:

585

answers:

2

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?

A: 

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

feihtthief
No, that only gives me the absolute path to the file in the file system. I need a URL (i.e. I need 'www.website.com/controls/FileUpload.asp' not 'c:\inetpub\wwwroot\website\controls\FileUpload.asp')
rdevitt
+3  A: 

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

Breadtruck
Yep. That's it. Stupid of me really.
rdevitt
No problem, as a matter of fact I always do it like that no matter what in case I move something around, add an extra folder or whatever.
Breadtruck
I actually ended up using Request.ServerVariables("URL") since I'm just posting back to the same page. This seems like a fairly consistent way to access the resource regardless of the server it's being hosted on and what subdirectories the site is in.
rdevitt
I agree with that. I actually have a little PageSetup include file with dim site_locationsite_location = lcase(Request.ServerVariables("URL")) This include file is all my pages and I use this for all my href url and actions unless I have a special circumstance. It also helps because when I change my pages I up my version naming scheme. blah_08.1.asp
Breadtruck
That's what I was going to say . . . I almost always use absolute paths just to avoid these kinds of problems.
tooshel