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

发布于 2024-07-09 18:35:38 字数 445 浏览 7 评论 0原文

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

http://someurl/

http://someurl/index.asp

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

谷歌搜索无法满足这一要求。 有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦明 2024-07-16 18:35:38

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

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.

套路撩心 2024-07-16 18:35:38

这个怎么样...
创建一个新文件 IndexDefault.asp 并将其设置为默认文档
在 IndexDefault.asp 中将其重定向到 Index.asp
在 IndexDefault.asp 中检查 IndexDefault.asp 的引荐来源网址。

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.

画▽骨i 2024-07-16 18:35:38

与之前的答案类似,但创建一个新页面,将其命名为 homepage.asp,其中包含 #INCLUDE FILE="index.asp" 或让它执行 index.asp 的 server.transfer 或 server.execute 将保存请求.ServerVariables 脚本名称与 homepage.asp 相同,因为请求对象一旦传递到 ASP 中就不会更改脚本名称。 然后您可以只测试这个值,而不必依赖引用者或必须进行重定向。 但这仍然意味着您必须更改默认文档。

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.

私藏温柔 2024-07-16 18:35:38

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

为了满足这是一个单一的、插入式代码的要求,我最终使用了这个 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>

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>
昔日梦未散 2024-07-16 18:35:38

Request.ServerVariables("REQUEST_URI").item 将为您提供客户端请求的原始 url,包括查询字符串部分。

它在 Request.ServerVariables 集合中不可枚举,并且没有一致记录,但它在 IIS 10 中适用于我。我在这里找到它: https://learn.microsoft.com/en-us/iis/web-dev-reference/server-variables

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文