The url will be used as part of an ajax call. JS won't understand ~, which is why I need the URL in the format ../../../page.
.net should work out the relative path and render it that way, so it is ~ in your code but ../../ etc in the html. If ~ doesn't do that then just setting the navigate url should.
Edit: I've just tested this and ~ does indeed produce a relative path.
cjjubb
Member
13 Points
58 Posts
Path To Root
Feb 01, 2013 01:14 PM|LINK
I need to use ASP.net to work out the path back to the root of my website.
For instance I need to turn the following url
/SecondLevelFolder/ThirdLevelFolder/FourthLevel/PageAtFourthLevel
into
../../../PageAtTheRootLevel
It need to be in the above format so I'cant use Server.MapPath.
Does anyone know how to do this?
AidyF
Star
9246 Points
1576 Posts
Re: Path To Root
Feb 01, 2013 01:16 PM|LINK
Have you tried using "~"?
NavigateUrl = "~/rootPage.aspx";
cjjubb
Member
13 Points
58 Posts
Re: Path To Root
Feb 01, 2013 01:24 PM|LINK
Thanks but unfortunately not.
The url will be used as part of an ajax call. JS won't understand ~, which is why I need the URL in the format ../../../page.
priyankmtr
Contributor
2626 Points
526 Posts
Re: Path To Root
Feb 01, 2013 01:28 PM|LINK
you can save the main url as back static keyword or constant like
_baseUrl = "http://www.mysite.co";
after that you can use this url in your project for accessing the other urls.
_baseUrl + "/home/mypage.aspx";
(Mark as Answer If you find helpful)
AidyF
Star
9246 Points
1576 Posts
Re: Path To Root
Feb 01, 2013 01:44 PM|LINK
.net should work out the relative path and render it that way, so it is ~ in your code but ../../ etc in the html. If ~ doesn't do that then just setting the navigate url should.
Edit: I've just tested this and ~ does indeed produce a relative path.
oned_gk
All-Star
35724 Points
7294 Posts
Re: Path To Root
Feb 01, 2013 02:41 PM|LINK
Suwandi - Non Graduate Programmer
oned_gk
All-Star
35724 Points
7294 Posts
Re: Path To Root
Feb 01, 2013 02:54 PM|LINK
Suwandi - Non Graduate Programmer