我怎样才能得到完整的 url 包括 # char 之后的字符
How can I get the full url including characters after a # char
我有以下代码:
<%@Language="VBSCRIPT"%>
<html>
<head>
<title>in/Test Page 2</title>
</head>
<body>
<%
response.write "Request.QueryString = """ & Request.QueryString & """<br />"
for each item in request.QueryString
response.write (item + " = " + Request.QueryString(item) + "<br>")
next
%>
</body>
</html>
当我用这个 url 调用它时:
TestPage2.asp?id=1&turl=http://www.google.com?id=1&url=generic#index
产生这个输出
Request.QueryString = "id=1&turl=http://www.google.com?id=1&url=generic"
id = 1
turl = http://www.google.com?id=1url=generic
如何获取原始 url 中 # 字符后的位?我已经查看了 Request.Servervariable 的所有内容。
简答:你不能
这是设计使然。
From RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax - Section 4.1 Fragment Identifier
When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch (“#”) character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.
基本上 #
永远不会发送到服务器,因此您无法从经典 ASP 中检索它。客户端 (Internet 浏览器) 在发送之前从 URI 中删除了 #
片段。
话虽如此,可以使用 JavaScript 从客户端检索它,然后通过表单/查询字符串将值传递到服务器,Classic ASP 可以检索并使用它。
我有以下代码:
<%@Language="VBSCRIPT"%>
<html>
<head>
<title>in/Test Page 2</title>
</head>
<body>
<%
response.write "Request.QueryString = """ & Request.QueryString & """<br />"
for each item in request.QueryString
response.write (item + " = " + Request.QueryString(item) + "<br>")
next
%>
</body>
</html>
当我用这个 url 调用它时:
TestPage2.asp?id=1&turl=http://www.google.com?id=1&url=generic#index
产生这个输出
Request.QueryString = "id=1&turl=http://www.google.com?id=1&url=generic"
id = 1
turl = http://www.google.com?id=1url=generic
如何获取原始 url 中 # 字符后的位?我已经查看了 Request.Servervariable 的所有内容。
简答:你不能
这是设计使然。
From RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax - Section 4.1 Fragment Identifier
When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch (“#”) character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.
基本上 #
永远不会发送到服务器,因此您无法从经典 ASP 中检索它。客户端 (Internet 浏览器) 在发送之前从 URI 中删除了 #
片段。
话虽如此,可以使用 JavaScript 从客户端检索它,然后通过表单/查询字符串将值传递到服务器,Classic ASP 可以检索并使用它。