If I understood the question.
Assumption
The full path is the path in the current application or child application. This is not a path limited by a parent, nor a path to a sister app. The desired path refers to the current application path.
Scenario 1
Path such as
"/someApp/SomeFolder/someSubFolder/file.ext"
must allow it: -
"~ / SomeFolder / someSubFolder / file.ext"
(although the designation ~ / is not what ASP classic understands).
Scenario 2
"/someApp/someSubApp/SomeSubFolder/file.ext"
do you still want: -
"~ / SomeFolder / someSubFolder / file.ext"
Scenario 3
The application is the root application of the site: -
"/SomeFolder/someSubFolder/file.ext"
will become anyway
"~ / SomeFolder / someSubFolder.file.ext"
Decision
The key to solving this is: -
Dim sAppMetaPath : sAppMetaPath = Request.ServerVariables("APPL_MD_PATH")
For the above scenario, this will lead to something like: -
- "/ LM / W3SVC / 33230916 / Root / someApp"
- "/ LM / W3SVC / 33230916 / Root / someApp / someSubApp"
- "/ LM / W3SVC / 33230916 / Root"
Besides
Dim sInstanceMetaPath: sInstanceMetaPath = Request.ServerVariables("INSTANCE_META_PATH")
will be returned in all scenarios
"/ LM / W3SVC / 33230916"
With some mathematical reduction, we can come to the function: -
Function ToAppRelative(virtualPath) Dim sAppMetaPath : sAppMetaPath = Request.ServerVariables("APPL_MD_PATH") Dim sInstanceMetaPath: sInstanceMetaPath = Request.ServerVariables("INSTANCE_META_PATH") ToAppRelative = "~/" & Mid(virtualPath, Len(sAppMetaPath) - Len(sInstanceMetaPath) - 3) End Function
AnthonyWJones
source share