Solved

Where am I?  Virtual directory, is there a variable with url?

Posted on 2000-05-09
4
240 Views
Last Modified: 2012-08-13
I thought the best way to handle this task was to use virtual directories, but if there is a better way, please don't hesitate to point me in that direction!  What I want to do is have a quick URL for each "product id" ..., e.g., "http://www.mydomain.com/apples/"   I currently as getting the functionality I want by having a single .asp sitting in the virtual directory that just sets the id ("apples") and then does an #INCLUDE FILE="../parent.inc" which is where all the vbscript and application logic exists.  

I'ld like to avoid having to place a unique .asp in each virtual directory.  I could do this if I could figure out how to determine dynamically which virtual directory got requested.  Is there a way?

I went down a tangent and followed the advice from Question #10236558
http://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=10236558 
I thought that was a great idea until I realized that the URL becomes messy then.  I wanted to keep it www.mydomain.com/apples/   (nice and clean, no filenames, extensions, question marks, etc.) as newbies will often be typing in the url manually.

Is there ANY way to get my vbscript .asp to know which virtual directory it is in?      Or is there an even simpler method of getting what I want without virtual directories, etc.,??
0
Comment
Question by:gorndog
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 100 total points
ID: 2792362
you can find out where you are by

Request.ServerVariables("SCRIPT_NAME") now the first bit returned will be the virtual dir if any.

now what you could do is have a single dir and have a default.asp that takes a param called topic

i.e

default.asp?topic=apples

then in default.asp

IF(Request("topic") = "apples")
    %>
       <!--#include file="apples.inc"->
    <%
END IF
IF(Request("topic") = "bannas")
   etc etc etc

each topic can have a corresponding .inc file. also any generic code thats relevant to all apps can reside in the default.asp .. such as titles headering setc.




0
 
LVL 10

Expert Comment

by:makerp
ID: 2792373
the script_name seems to be the one for you.

so just have your virtual dirs and chop the first bit of script_name. then redirect to a correwsponsing file. include a file etc.

vdir = Mid(Request.ServerVariables("SCRI{PT_NAME"),0,(Instr(Request.ServerVariables("SCRIPT_NAME"),"/")))

should get the virtual dir
0
 
LVL 4

Expert Comment

by:fruey
ID: 2792392
All of your virtual directories can point to the same physical directory. Then you can have one script that grabs the virtual directory name with a

Request.ServerVariables("URL")

Otherwise, you could have a box on the homepage where you type the product name to get redirected via an ASP; but this won't give you the possibility to type the URL manually to point directly to a product name.

Alternatively you could allow the URL to generate a 404 BUT have your 404 file configured as a "normal" asp page which then redirects based on the info, which will be in the QueryString. However, this is messy.
0
 

Author Comment

by:gorndog
ID: 2794905
All three responses were right on!  (Unfortunately Experts-Exchange won't let me split the points.)

Both server variables ("Script_Name", and "URL") return the name of the virtual directory.  (I thought I had tried "script_name" before I had asked the question but I must have overlooked something.)  So I can use either one.

Then another thing that saved me was the ability to have a "default document" for the virtual directory.  That let me hide all the .asp names and everything else.  So what I'm left with is one single, simple .asp which simply extracts the directory name from the "URL" server variable ( e.g., URL returns  "/apple/default.asp") and then from there the program flow is data driven..

That is EXACTLY what I wanted to do.  Thank you, thank you, thank you!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get statistic's from a competitors website?! 1 112
Pass through dll 2 91
Save ms data to server side. 19 55
Connecting to multiple databases to create a Dashboard 5 47
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question