【问题标题】:how to find subdomain from current URL ASP-Classic如何从当前 URL ASP-Classic 中查找子域
【发布时间】:2016-08-03 05:51:40
【问题描述】:

我正在尝试编写单个脚本源与不同数据库通信但数据库名称来自子域名的小脚本。目前我做了以下测试并遇到问题,无法自行修复。问题是,当一个用户在浏览器中打开许多子域选项卡时,持续 90 秒或 2 分钟,第一个请求的响应将与另一个所有请求的响应相同。

例如网址:

http://user1.domains.com/subdomaintest.asp

https://user1.domains.com/subdomaintest.asp

http://user2.domains.com/subdomaintest.asp

http://user3.domains.com/subdomaintest.asp

http://user4.domains.com/subdomaintest.asp

http://user5.domains.com/subdomaintest.asp

首先我打开http://user1.domains.com/subdomaintest.asp 然后打开http://user2.domains.com/subdomaintest.asp 并得到相同的响应h1text(user1),这是意料之外的。它必须以 user2 的身份响应 h1text。假设我在 2 分钟后打开第二个 url,然后响应 user2,这没关系。 GUID 也相同,似乎与响应相同。

我想要的是,响应必须随时依赖子域名,而不是 2 分钟后。如果这是 IIS 问题,它是什么问题,我可以在哪里更改?还如何将 GUID 实现到浏览器选项卡和/或会话中?

代码如下:

'ServerName = Request.ServerVariables("HTTP_HOST")
ServerName = Request.ServerVariables("SERVER_NAME")
arrSplitted = Split(ServerName, ".")
SubDomain = arrSplitted(0)
'response.write(SubDomain)
response.write "<h1>" & SubDomain & "</h1>"
Response.Write "<h1>"& CreateGuid() &"</h1>"
Function CreateGuid()
    CreateGuid = Mid(CreateObject("Scriptlet.TypeLib").Guid,2,36)
End Function

我在 HTTP HEADER 上做了很多阅读,并找出了 Request.ServerVariables("SERVER_NAME") 和 Request.ServerVariables("HTTP_HOST") 的区别。

response.write Request.ServerVariables("SERVER_NAME")
response.write Request.ServerVariables("HTTP_HOST")

但这对我没有帮助。我也尝试过响应cookie,但它是一样的。似乎 IIS 不在乎我从不同的子域请求 2 分钟。这是为什么呢?

关于服务器:IIS10,sessionstate false(我没有使用),64bit。相关的任何信息,你可以问我。

任何人帮助我,非常感谢你提前!请帮忙!

【问题讨论】:

  • 您是否使用了从域 user1 到 user2 的任何 URL 重定向或 URL 重写?

标签: session vbscript asp-classic iis-7.5 iis-10


【解决方案1】:

恕我直言,你几乎做对了所有事情

但是,我想你弄乱了位置。你只需要检查一级子域,它的索引为UBound(X) - 1

<%
  Dim LServerName, LNames, LCycle
  LServerName = Request.ServerVariables("SERVER_NAME")

  Response.Write "<br>Full server name: " & LServerName

  If LServerName <> "" Then
    LNames = Split(LServerName, ".")

    For LCycle = LBound(LNames) To UBound(LNames)
      Response.Write "<br>Level #" & LCycle & ": " & LNames(LCycle)
    Next

    Response.Write "<br>UBound: " & UBound(LNames)

    If UBound(LNames) > 0 Then
      Response.Write "<br>Top level domain is: " & LNames(UBound(LNames))
      Response.Write "<br>1st level subdomain is: " & LNames(UBound(LNames) - 1)
    End If 

    If UBound(LNames) > 2 Then
      Response.Write "<br>2nd level subdomain is: " & LNames(UBound(LNames) - 2)
      Response.Write "<br>3rd level subdomain is: " & LNames(UBound(LNames) - 3)
    End If
  End If
%>

【讨论】:

  • 感谢您的回复。但这是同样的问题。我只是复制粘贴了您的代码并刷新了我所有打开的标签,子域名是相同的。我也相信代码,我的代码或你的代码没有问题。但我找不到问题所在。为什么 iis 只响应第一个请求的正确响应?
  • 很奇怪。链接到我的家庭服务器上的代码:http://1click.sdk.1click.lv/test.asphttp://x2.sdk.1click.lv/test.asp。同一个网站,绑定名称很少。 64 位操作系统上的 IIS 7.5
  • 你的那两个链接/文件在同一个文件和目录中吗?真的很奇怪。我在 5 秒内都打开了您的链接,并且它们的响应都是正确的。那为什么我的不是呢?
【解决方案2】:

我自己发现了问题。

网络服务器是 iis 10,它支持通配符出价,我在网站上使用了许多 80 和 443 出价,包括通配符子域和实时网站。一切都在一个文件夹中,网站有一个应用程序池和一些其他配置。

问题出在会话上。

我读了这么多文章,寻找解决方案,它们都不起作用。然后我确定这是会话问题并尝试使用不同的网站进行测试。是的,为测试创建了不同的应用程序池和网站。经过测试,一切正常。

问题出在会话中,而不是代码。

【讨论】:

    猜你喜欢
    • 2011-06-20
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 2021-06-25
    相关资源
    最近更新 更多