views:

82

answers:

3

I'm trying to get the previous page URL after I do a response write and i've looked around the web and people are using HTTP_REFERER but that doesn't work with Response.Redirect so is there anyway to get the URL of the previous page?

I have this code on a few pages and i need to know which page it is coming from when it gets to the servererror/default.aspx page

 Response.Redirect("servererror/default.aspx?404")

And on my servererror/default.aspx page i'm just trying to grab the previous page URL and put it into the Session Session("ErrorPage")

Thanks

Jamie

UPDATE

I have now got it to work like this

Response.Redirect("server-error.aspx?404&" & Request.Url.ToString())

That passes the URL of the page with the error to the next page and I then grab that from the Query String

Thanks

Jamie

+1  A: 

Hey,

You could try server.transfer instead to see if it populates the HTTP_REFERER value.

Brian
This does not populate the referrer field, but I believe it would populate the ClientFilePath as this is what they originally requested, and you then transfered them.
jimplode
+4  A: 

You can pass the URL of the previous page to the error page's URL. something like

Response.Redirect("servererror/default.aspx?404&url=/folder/page.aspx")

And then get the url value on the error page and redirect it to the previous page.

rauts
This is the best solution, this is the approach most sites out there take.
jimplode
specially as HTTP_REFERER could be blocked all around in the browser (privacy)
eglasius
Jamie Taylor
glad i could help. cheers
rauts
A: 

Keep in mind what Response.Redirect is doing: It is issuing a 302 "found" to the client. This response code is meant to indicate that the content you are seeking is not in the location you requested, but instead is elsewhere.

Given that info; the page that issues the Response.Redirect is not actually the 'referrer' at all, then. This is why the page that referred to that page is still reported as the referred.

As rauts noted above, you should include in the URL string you are redirecting to any extra information you need, such as the current page's URL

Andrew Barber