Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Absolute/Relative URLs in user controls

Status
Not open for further replies.

Silo4

Programmer
Nov 7, 2002
17
GB
Hi,

I have an ASP.NET 1.1 website with as ASCX control for the header which includes a link to a page. Why is it that when i upload my site, i have to manually change the absolute URL paths?

After much messing i've discovered that locally they have to be...

Code:
/MyWeb/MyPage.aspx

but on the web they need to be just...

Code:
/MyPage.aspx

I have looked all over the net for an answer to this but found very little. Neither of these suggestions seems to work...

Code:
~/MyPage.aspx

or

Code:
<%ResolveUrl("~/MyPage")%>"

Does anyone know of a common method that would work both locally and on the host server? Surely I don't have to manually change my code every time i want to upload, then back again when i want to test locally?

Any help would be greatly appreciated.

Silo4
 
Sib4: From my experience if you are buried withing subfolders 1 or 2 deep, for example, the following works for me:

"../Folder1/Folder2/MyPage.aspx"

..or..

"./Folder1/Mypage.aspx"

But this has been my experience. Give that a try and see what you come up with.
 
Cheers for that, but the problem is that the ASCX control thinks of itself as being located in the same folder as the page it is attached to. So if I use a relative url it will work for any pages in the same folder but not for pages in other folders. For Example...

"../Folder1/MyPage.aspx"

will work from "../Folder2/TestPage.aspx"

but will not work from "../Folder2/Folder3/TestPage.aspx"

because it is then looking for "../Folder2/Folder1/MyPage.aspx"

Does that make sense?

I guess it's because Visual Studio wants to refer to the IIS virtual directory, but i can't believe there isn't a way round it. It's so frustrating.

Any other ideas?
 
Silo4: the answer to this is probably straightforward. Did you try using:

Server.MapPath("MyPage.aspx;")

..actually this does work but something strikes me it may not be what we're after here; just a shot in the dark as it were.
 
..or how about

"~/MyPage.aspx"

..w/o the ResolveUrl tag..
 
Cheers again for the suggestions, i have tried for another hour to figure something out but nothing works both remotely and local. I give up, I'll have to do it manually.

Thanks for your help.

I can't believe no-one else seems to have this problem!
 
Silo4: I can relate. I have burnt untold precious hours only in the end to discover it was nothing more complicated then ABC - etc, I suppose that is why they call it a learning process.

Here's a thought. Sometimes, when I hit a dead end like you have I tend to go back and see if it wasn't the original design that was to blame - in this case perhaps not -- but there are many out there who should be able to nail this; so hang in there. We'll bump this thread up with suggestions till we nail it - without of course making ourselves a nuisance in the process. But a good question -- perhaps a full link is the answer here - but I think you are right; it is peculiar to the "ascx" page itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top