2

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?

casperOne
  • 73,706
  • 19
  • 184
  • 253
rmdaustin
  • 21
  • 1
  • Have you used a basic iterator over the Request.ServerVariables to figure out if there are any that *could* be used? I'm not in front of my machine right now, so I can't test... – BenAlabaster Dec 18 '08 at 00:56
  • for each s in request.servervariables next – rmdaustin Dec 18 '08 at 01:03
  • I misread your question, but yes I tried that. In addition to the three I listed, the only other variable that contains the script name is "PATH_TRANSLATED," but that's a physical path and it doesn't change for the default document. – rmdaustin Dec 18 '08 at 01:18

5 Answers5

1

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 - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
0

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
  • 34,542
  • 18
  • 104
  • 162
  • 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 Dec 18 '08 at 01:15
  • Actually, this doesn't work. A server-side response.redirect doesn't appear to set HTTP_REFERER. – rmdaustin Dec 18 '08 at 04:20
  • 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 Dec 18 '08 at 10:17
  • 1
    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 Jan 07 '09 at 00:09
0

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.

0

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
  • 21
  • 1
0

Request.ServerVariables("REQUEST_URI").item will give you the raw url requested by the client including the query string portion.

It is not enumerable in the Request.ServerVariables collection and it's not documented consistently but it works for me in IIS 10. I found it here: https://learn.microsoft.com/en-us/iis/web-dev-reference/server-variables