2

I have the following code:

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

When I call it with this url:

TestPage2.asp?id=1&turl=http://www.google.com?id=1&url=generic#index

Which produces this output

Request.QueryString = "id=1&turl=http://www.google.com?id=1&url=generic"
id = 1
turl = http://www.google.com?id=1url=generic

How do I get the bit after the # char in the original url? I've looked all through the Request.Servervariable's.

RichJohnstone
  • 467
  • 1
  • 3
  • 10

1 Answers1

3

Short answer: You can't


It's by design.

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.

Basically the # is never sent to the server so you can't retrieve it from Classic ASP. The client (Internet Browser) removes the # fragment from the URI before it is sent.

Having said that it is possible to retrieve it from the client-side using JavaScript then pass the value via a form / querystring to the server where Classic ASP can retrieve and use it.

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • Can you recommend the JavaScript to use for this? – WilliamK Apr 17 '19 at 22:29
  • @WilliamK setup a hidden `` then use [tag:javascript] to [extract the hash from `location`](https://stackoverflow.com/a/13344286/692942) and update the hidden `` so when the `
    ` is submitted you can then use `Request.Form` to access the hash value.
    – user692942 Apr 18 '19 at 23:20
  • I was trying to get the referrer link to track search referrals, but it seems that Google has changed some things and that may not be possible. But there is no form to submit on normal web pages that I want to track, unless you are suggesting that I add a hidden one. Anyways, I would need an example of code to try that. – WilliamK Apr 19 '19 at 00:06
  • @WilliamK it doesn't have to be a `
    ` just needs to post the value to a ASP page, you could do that with an AJAX call. There are already examples of retrieving the `location.hash` in the link I provided, you can find numerous approaches to posting via AJAX so you have all the information you need.
    – user692942 Apr 19 '19 at 07:03
  • @WilliamK here is an [example of using AJAX to post to Classic ASP](https://stackoverflow.com/a/32100168/692942). – user692942 Apr 19 '19 at 07:09
  • It seems that code needs to be on the referring page, which is on a Google server. Because the referrer string has already been stripped of their params. I c an already get that using the server variable for HTTP_REFERER .All I get these days is my part of the link as it arrives. – WilliamK Apr 19 '19 at 22:28