Small ASP cheat sheet: getting current path (absolute URL), getting current script name.

Again I’d like to present small collection of solutions for my not favorite technology (not confuse it with ASP.NET which I respect).

When need get the default URL for the current sub folder (that can be used for example to present a link on this section of site in mail), can be used following code:

‘ getting absolute path for current sub folder

path = Left(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)

‘ if url need for a putting in email for example, so protocol and server name must e added

url = “http://” & Request.ServerVariables(“SERVER_NAME”) & path

Also can be helpful getting the name of current script (for a generating conditional dependent content for example), following peace of code will helpful:

file = Right(Request.ServerVariables(URL),Len(Request.ServerVariables(URL)) - Len(path))

In this case we use the path variable that need get before, and if we’d like to get file without calculate it, we should use following code:

file = Mid(Request.ServerVariables(URL),InstrRev(Request.ServerVariables(URL),“/”)+1)

No Responses so far »

Comment RSS · TrackBack URI

Say your words