Get previous URL after Response.Redirect

I try to get the previous URL of the page after I write the answer, and I browsed the web and people use HTTP_REFERER , but this does not work with Response.Redirect, so anyway, to get the URL of the previous page?

I have this code on several pages and I need to know which page it appears on when it gets to the servererror/default.aspx page

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

And in my servererror/default.aspx page, I'm just trying to grab the previous page URL and put it in a Session("ErrorPage") session

thanks

Jamie

UPDATE

Now it works for me, like this

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

This passes the URL of the error page to the next page, and then I get it from the query string

thanks

Jamie

+4
source share
4 answers

You can pass the URL of the previous page to the URL of the error page. sort of

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

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

+6
source

Instead, you can try server.transfer to see if it fills the HTTP_REFERER value.

+2
source

Keep in mind what Response.Redirect does: it gives 302 β€œfound” to the client. This response code is intended to indicate that the content you are looking for is not in the place you requested, but instead is in another place.

Given this information; the page that issues Response.Redirect is not really a referrer. This is why the page that linked to this page is still reported as a link.

As stated above, you must specify in the string the URL that you redirect to any additional information, for example, to the current URL of the page

+2
source

I know his old message to answer. Even the guy who posted this question found some solution to solve his question ............. but last night yesterday I faced the same difficulty so I came with a workaround that works on my case ...

I have 2 pages Page1.aspx and Page2.aspx I have Button1 and Button2 on page1.aspx now that the script is when I redirect to the page. ASP.NET, I want to access the Page1.aspx controls, which is called the previous page ..... So I use the PostBackURL buttons, but in this case I did not get the Click event on CodeBehind ........ since I have to solve this problem ............. What I did was that I set Button2.PostBackURL = "Page2.aspx", and when the Button1 Click event fires, I I register the start of the script that triggers the Button2.click event, so now I get the previous control page ..........

Here is the code ..... if someone is looking for the same functionality ............ they will be helped in a sense ........

Aspx Code

 <asp:Button ID="btnSave" runat="server" Style="font-weight: 700" Text="Save" onclick="btnSave_Click" /> 

Code-behind

  protected void btnSave_Click(object sender, EventArgs e){ try { StringBuilder objStringBuilder = new StringBuilder(); objStringBuilder.AppendLine("<script type='text/javascript' language='javascript'>"); objStringBuilder.AppendLine("document.getElementById('" + btnHidden.ClientID + "').click();"); objStringBuilder.AppendLine("</script>"); ClientScript.RegisterStartupScript(Page.GetType(),"Key1", objStringBuilder.ToString()); } catch (Exception ex) { throw ex; }} 

Respectfully,

+1
source

All Articles