Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding previous page Url

Tags:

asp.net

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

like image 631
Searock Avatar asked Apr 21 '09 14:04

Searock


People also ask

How do I find Windows history?

In Windows 10, select Start , then select Settings > Privacy > Activity history. In Windows 11, select Start , then select Settings > Privacy & security > Activity history.

How do I find the previous URL in node JS?

You have to store in session. app. get('/url1', function(req, res){ res. send('ok') req.

What is document referrer?

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.

Why is document referrer empty?

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.


1 Answers

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.

like image 110
Cros Avatar answered Oct 26 '22 08:10

Cros