I want to grab the url of the previous page from the current page

Joined
Jul 3, 2008
Messages
1
Reaction score
0
Method 1
If Not Request.UrlReferrer.ToString() Is Nothing Then
Label1.Text = Request.UrlReferrer.AbsoluteUri.ToString()
Else
Label1.Text = "default url"
End If

Method 2
If Not Request.ServerVariables("HTTP_REFERER") Is Nothing Then
Label1.Text = Request.ServerVariables("HTTP_REFERER")
Else
Label1.Text = "default url"
End If

There are 2 aspx pages page1.aspx and page2.aspx. Page1 has a hyperlink which is linked to Page2 and page 2
has a label control
which displays the url of the previous page. I want to get the url of the previous page from the current page.
I tried using the above given method.
Both methods work fine but when i go to page2(pasting the url in page2 directly without clicking the page1 hyperlink) directly when using method 1 i get the exception message
"System.NullReferenceException: Object reference not set to an instance of an object."
But when i use method 2 and go to page 2 directly its works fine. Please tell me which is the best
possible way to do this and if there is any other way of doing this please let
me know. I want to grab the url of the previous page from the current page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top