rsturim
rsturim

Reputation: 6846

How do I retrieve the referrer page url once a custom error page is returned

I'd like to capture the http referrer url following the rendering of a custom error page.

I have this set in my web.config

<customErrors mode="On">
  <error statusCode="500" redirect="/StaticError.aspx" />
</customErrors>

In the OnLoad(EventArgs e) event -- I'm trying to do this, but it appears to be too late.

this.txtReferrer.Text = Request.UrlReferrer.ToString();

Is it possible to capture the referrer url?

Upvotes: 2

Views: 2103

Answers (1)

Joe King
Joe King

Reputation: 66

On your custom error page (/StaticError.aspx), Request.UrlReferrer will be the page that referred/posted to the page that is erroring. If your first request to the website is the erroring page, it will be blank, as there is no referrer.

If you are looking for the page that actually errored, it will be posted to the query string when directed to your custom error page.

VB.NET

this.txtReferrer.Text = Request.QueryString("aspxerrorpath")

C#

this.txtReferrer.Text = Request.QueryString["aspxerrorpath"];

Upvotes: 4

Related Questions