Control Freak
Control Freak

Reputation: 13233

Getting Referer from Custom 404 page

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?

Upvotes: 3

Views: 1253

Answers (2)

devdrc
devdrc

Reputation: 2127

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>

Upvotes: 0

AnthonyWJones
AnthonyWJones

Reputation: 189467

The simple answer to this is: no.

Upvotes: 4

Related Questions