Solved

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

Posted on 2000-05-09
4
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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