【问题标题】:get current url of the page (used URL Rewrite)获取页面的当前 url(使用 URL Rewrite)
【发布时间】:2013-03-01 23:25:36
【问题描述】:

我正在开发经典的 asp 应用程序。 我在某些页面上使用了 URL 重写。

如何在经典asp中获取页面的当前url?

示例: http://www.site.com/page.asp ---> IIS 中的 url 重写 ---> http://www.site.com/home/page

所以这里我想要页面的当前网址,即http://www.site.com/home/page

请帮助我。 谢谢。

【问题讨论】:

  • 你不能用Request.ServerVariables("server_name") & Request.ServerVariables("url") 阅读它吗?不确定这是否也适用于重写的网址......
  • 没有 Request.ServerVariables("server_name") = www.site.com 和 Request.ServerVariables("url") = page.asp
  • 如果这些答案对您有帮助,请您标记一下吗?如果没有,请告诉我们,以便我们找到解决方案。

标签: asp-classic vbscript


【解决方案1】:

如果使用 URL Rewrite,则只能通过这种方式检索 url 数据:

Request.ServerVariables("HTTP_X_ORIGINAL_URL")

例子

Dim domainName, urlParam
domainName = Request.ServerVariables("SERVER_NAME") 
urlParam   = Request.ServerVariables("HTTP_X_ORIGINAL_URL")
response.write(domainName & urlParam)

【讨论】:

    【解决方案2】:

    您可以尝试像这样输出所有 ServerVariables:

    for each key in Request.Servervariables
      Response.Write key & " = " & Request.Servervariables(key) & "<br>"
    next
    

    也许您寻找的网址已经存在。我们使用 Rewrite 模块,并且有一个名为 HTTP_X_ORIGINAL_URL 的 ServerVariable 包含重写的 URL 路径,例如在您的示例中为“/home/page”。

    协议 (HTTPS=ON/OFF) 和服务器 (SERVER_NAME) 也可以在 ServerVariables 中找到。

    【讨论】:

      【解决方案3】:

      没有一种功能可以做到这一切。

      首先你需要得到协议(如果它不总是http):

      Dim protocol
      Dim domainName
      Dim fileName
      Dim queryString
      Dim url
      
      protocol = "http" 
      If lcase(request.ServerVariables("HTTPS"))<> "off" Then 
         protocol = "https" 
      End If
      

      现在剩下的都是可选的查询字符串:

      domainName= Request.ServerVariables("SERVER_NAME") 
      fileName= Request.ServerVariables("SCRIPT_NAME") 
      queryString= Request.ServerVariables("QUERY_STRING")
      
      url = protocol & "://" & domainName & fileName
      If Len(queryString)<>0 Then
         url = url & "?" & queryString
      End If
      

      希望它对你有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-17
        • 2012-07-17
        • 1970-01-01
        • 2016-09-28
        • 1970-01-01
        • 1970-01-01
        • 2021-07-23
        相关资源
        最近更新 更多