如何确定默认文档是否在传统ASP中提供?

时间:2022-06-20 04:37:25

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:

在一个名为index.asp的文件中,它在IIS中设置为目录的默认文档,我试图通过.asp VBScript确定该页面是否作为默认文档而不是直接按名称调用,即我是试图区分服务器端这两种情况:

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.

我知道如何在ASP.NET中执行此操作,但似乎没有相同的“服务器变量”。无论脚本调用的方式如何,处理URL和脚本名称(PATH_ INFO,SCRIPT_NAME,URL)的服务器变量都返回“index.asp”。

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

谷歌搜索不足以解决这个问题。有任何想法吗?

4 个解决方案

#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.

服务器不会知道,但客户端会。在JavaScript中,您可以检查location.href,然后使用对所需记录机制的Ajax调用将该值传递回服务器。

#2


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.

怎么样...创建一个新文件IndexDefault.asp并将其设置为默认文档在IndexDefault.asp中使其重定向到Index.asp在IndexDefault.asp中检查IndexDefault.asp的referrer。

#3


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.

与之前的答案类似,但是创建一个新页面,将其称为homepage.asp,它具有#INCLUDE FILE =“index.asp”或者让它执行server.transfer或server.exe的index.asp将保存请求作为homepage.asp的.ServerVariables脚本名称作为请求对象,一旦传递给ASP,就不会改变脚本名称。然后你可以测试这个值,你不必依赖referrer或者必须进行重定向。这仍然意味着你必须更改默认文档。

#4


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).

Diodeus是正确的,客户端JavaScript似乎是检测URL的唯一方法。所有其他选项都需要将内容页面和默认文档页面区分为单独的文件。所有我真正想要做的就是将两个请求压缩到默认文档URL中(在直接请求index.asp的情况下重定向)。

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

为了满足这是一个单独的代码片段的要求,我最终使用了这个JavaScript块:

<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>

#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.

服务器不会知道,但客户端会。在JavaScript中,您可以检查location.href,然后使用对所需记录机制的Ajax调用将该值传递回服务器。

#2


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.

怎么样...创建一个新文件IndexDefault.asp并将其设置为默认文档在IndexDefault.asp中使其重定向到Index.asp在IndexDefault.asp中检查IndexDefault.asp的referrer。

#3


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.

与之前的答案类似,但是创建一个新页面,将其称为homepage.asp,它具有#INCLUDE FILE =“index.asp”或者让它执行server.transfer或server.exe的index.asp将保存请求作为homepage.asp的.ServerVariables脚本名称作为请求对象,一旦传递给ASP,就不会改变脚本名称。然后你可以测试这个值,你不必依赖referrer或者必须进行重定向。这仍然意味着你必须更改默认文档。

#4


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).

Diodeus是正确的,客户端JavaScript似乎是检测URL的唯一方法。所有其他选项都需要将内容页面和默认文档页面区分为单独的文件。所有我真正想要做的就是将两个请求压缩到默认文档URL中(在直接请求index.asp的情况下重定向)。

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

为了满足这是一个单独的代码片段的要求,我最终使用了这个JavaScript块:

<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>