Get previous page URL after Response.Redirect

Jamie Taylor picture Jamie Taylor · Sep 27, 2010 · Viewed 27.9k times · Source

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

Answer

rauts picture rauts · Sep 27, 2010

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.