views:

178

answers:

4

In a file called index.asp, which is set up in IIS as a default document for the directory, I'm trying to determine via .asp VBScript if the page was called as the default document versus directly by name, i.e. I'm trying to distinguish between these two cases server-side:

http://someurl/

http://someurl/index.asp

I know how to do this in ASP.NET, but the same "server variables" don't seem to be available. The server variables that do deal with the URL and script name (PATH_ INFO, SCRIPT_NAME, URL) all return "index.asp" regardless of which way the script is called.

A Google search falls short on this one. Any ideas?

A: 

How about this...
Create a new file IndexDefault.asp and set it as the default document
In IndexDefault.asp make it a redirect to Index.asp
In IndexDefault.asp check the referrer for the IndexDefault.asp.

JohnFx
I thought about this, and it would work for the purpose, but I was asked for a drop-in piece of code, and the client will push back on having to rework all the default document setups on the site. I'll mark this as the answer if no one comes up with a purely programmatic way to do it.
rmdaustin
Actually, this doesn't work. A server-side response.redirect doesn't appear to set HTTP_REFERER.
rmdaustin
You could have a meta refresh-tag that redirect the page instead of a server redirect. Javascript-redirect is not a good solution if javascript is disabled.
Stefan
mdaustin. It doesn't work because I neglected a step. Instead of using the HTTP_Referer just make the redirect link include a querystring parameter that the target page can look for to identify a re-routed request.
JohnFx
+1  A: 

The server won't know, but the client will. In JavaScript you can examine the location.href, then pass that value back to the server using an Ajax call to whatever logging mechanism you want.

Diodeus
If its accepted do use javascript for this, then this solution is the best I think. +1
Stefan
A: 

Similar to an earlier answer, but creating a new page, call it homepage.asp, which has either #INCLUDE FILE="index.asp" or having it do a server.transfer or server.execute of index.asp would hold the Request.ServerVariables script name in tact as homepage.asp as the request object won't change script name once it is passed into ASP. Then you could just test on this value, and you wouldn't have to rely on referrer or have to do the redirect. This would still mean you gotta change default document though.

A: 

Diodeus is correct, client-side JavaScript seems to be the only way to detect the URL. All the other options require differentiating the content page and the default document page into separate files. All I'm really trying to do it condense both requests down into the default document URL (redirecting in the case where index.asp is requested directly).

To satisfy the requirement that this be a single, drop-in piece of code, I ended up using this JavaScript block:

<script language="javascript" type="text/javascript">
var loc = window.location.href;
var re = /\/index.asp/i;
if (loc.search(re) != -1) {
    window.location.href = loc.replace (re,"/"); 
}
</script>
rmdaustin