Solved

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

Posted on 2000-05-09
4
236 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now