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 wi
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
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.
You could try server.transfer instead to see if it populates the HTTP_REFERER value.
I know its a old post to reply Even the guy who have posted this question has found some workaround for solving his question............. but late yesterday night i was facing the same difficulty so i have come with a workaround which is working on my case...
I have 2 Pages Page1.aspx and Page2.aspx I have a Button1 and Button2 on the Page1.aspx now what the scenario is when i redirect to Page2.aspx i want to access Page1.aspx controls which is called Previous Page..... So i use PostBackURL of a button but in that case i was not getting the Click Event on CodeBehind......... so how should i solve this issue............. What i did is that i set the Button2.PostBackURL = "Page2.aspx" and when the Button1 Click event triggers i am registering the startup script which calls Button2.click event so now i am getting the Previous page controls..........
Here is the code..... if somebody looking for same functionality............ they will be helped in some 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;
}}
regards,