i am trying to find the url of previous page.Such as if a user navigates from Page A to Page B using Server.Redirect("B.aspx")
, page B can display the url referring to it.
I have tried using
Response.Write(Page.PreviousPage.ToString());
Response.Write(Request.UrlReferrer.ToString());
Response.Write(Context.Request.UrlReferrer.ToString());
Response.Write(Request.ServerVariables["HTTP_REFERER"].ToString);
but all in vain it gives me null exception
error
In Windows 10, select Start , then select Settings > Privacy > Activity history. In Windows 11, select Start , then select Settings > Privacy & security > Activity history.
You have to store in session. app. get('/url1', function(req, res){ res. send('ok') req.
document. referrer gives you the URI of the page that linked to the current page. This is a value that's available for all pages, not just frames. window. parent gives you the parent frame, and its location is its URI.
For security/privacy reasons, the Referer URL is stripped out when navigating from a HTTPS site to a HTTP site (e.g. from https://google.com to http://example.com). It can also be deliberately stripped out via a variety of JavaScript and HTML tricks.
You can save you current page in the Session and then retrieve it from there:
string previousPage = Session["PreviousPage"] as string;
Session["PreviousPage"] = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.FilePath);
This way the previousPage string will always contain the previous page's filename, and the Session variable will contain the current page, ready to be used on the next page.
This way you can also detect if the referrer is an outside link because then the previousPage string will be null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With