3

The custom 404 error only gives you the page that was not found when using Request.Servervariables("QUERY_STRING") , Well aware of this.

But how do you get the referer of that page?

Request.Servervariables("HTTP_REFERER") in the custom 404 error page, does NOT return the referring page of the page which calls the 404 page.

The pages are in this order:

  1. Referring Page to Invalid URL (/home/)
  2. Invalid URL (/invalidurl)
  3. 404 Error Page (/404)

I'm trying to get the Referring page (1) from the 404 Error Page (3), not the Invalid URL (2) as you do by using the Request.Servervariables("QUERY_STRING")

Any suggestions?

Control Freak
  • 12,965
  • 30
  • 94
  • 145

2 Answers2

4

The simple answer to this is: no.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
0

You can't easily do this on the server side, but you can on the client side, since the browser keeps history. You just have to use -2 in the history.back method.

HTML

<a id="goBack">Back</a>

JS

<script>
document.addEventListener("DOMContentLoaded", function(){
    document.getElementById('goBack').addEventListener('click', () => {
        history.back(-2);
    });
});
</script>
devdrc
  • 1,853
  • 16
  • 21