Solved

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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