Link to home
Start Free TrialLog in
Avatar of boricua1213
boricua1213

asked on

Get relative path?

How to get relative path from root.  In asp.net i can use ResolveUrl("~/page.aspx') to get the path from where ever the user is at in the directory structure back to root to get to page.aspx.  Is there a way to do this in classic ASP?
Avatar of jitganguly
jitganguly

Sever.Mappath(("~/page.aspx')
Avatar of boricua1213

ASKER

Wouldn't that give me the physical path?  C:\site\page.aspx
Ok Try this

request.servervariables("path_info")
Avatar of Mark Franz
So what is it you want?  The following script;

<%
Response.Write Request.ServerVariables("PATH_INFO") & "<br>"
Response.Write Request.ServerVariables("PATH_TRANSLATED") & "<br>"
Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH") & "<br>"
Response.Write Request.ServerVariables("SCRIPT_NAME") & "<br>"
Response.Write Request.ServerVariables("SERVER_NAME") & "<br>"
Response.Write Request.ServerVariables("URL") & "<br>"
%>

Provided these results;

/scripts/path.asp
C:\Inetpub\wwwroot\scripts\path.asp
c:\inetpub\wwwroot\
/scripts/path.asp
localhost
/scripts/path.asp
Say I am viewing a page in here: www.asdf.com/dir/test.asp

and in test.asp I want to know how to get to www.asdf.com/scripts/test.js

Now in Asp.net I can use ResolveUrl("~/scripts/test.js")  that will return ../scripts/test.js if it was an aspx page.  That is what I need in asp.

U might be thinking oh just put a slash in front the resource like "/scripts/test.js".  In this example this will work, but if the applications root was in a directory below the domains root, such as: www.asdf.com/app/dir/test.asp.  Now if I try to use the slash the browser will look for test.js at www.asdf.com/scripts/test.js.  But it is actually at www.asdf.com/app/scripts/test.js.  In ASP.net the ResolveUrl will return the correct URL.

You might be asking your self y i'm i using asp instead of .net.  I need to set a variable in third party asp app.

Thank you in advance
ASKER CERTIFIED SOLUTION
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My input seems to be the best response.
How would I use this function to set a vir_path to a file? To get away from all the ../../ in the includes on asp pages.
Example; wwwroot/folder1/folder2/folder3/somefile.asp
So all the includes would point to virtual/scripts/pathfile.asp