Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I know this is a simple thing, usually, but for some reason I just can't figure out how to do it:

 

On my Page_Load Event (.vb side), I need to capture the URL from the previous (referring) page and hold it in a variable or in a label that is not visible on my page.

 

An example:

I got to http://www.yahoo.com and click on Yahoo! Auctions. On the Page_Load Event of the Yahoo! Auctions page, I need to set myurl = http://www.yahoo.com.

 

Can anyone tell me how to do this using VB.NET?

Posted
I know what your talking about, I've done it in the past, just can't find the code, check MSDN under the window or document object; one of those if I remember right has a property for the previous page... sorry that's all I got, someone I'm sure will give you the exact though.
Posted (edited)

I have tried using Request.UrlReferrer and I always get an error.

Below is the code I used:

 

Private myurl As Uri

myurl = Request.UrlReferrer 'in my page_load event

 

Response.Redirect(myurl.AbsoluteUri) 'button_click event

 

I am probably way off base an completely wrong in the way that I am trying to do this, but I found an article on msdn where they said to do it this way. The error that I get says that the Object reference is not set to an instance of an object (my favorite error...). When stepping through the code in debug mode, I see that when I am tryiing to set the myurl variable, it is = to nothing.

 

Does anyone know what I'm doing wrong?

Edited by devylzangel
  • *Gurus*
Posted
Unless Request.UrlReferrer is a null reference then Response.Redirect(Request.UrlReferrer.ToString()) should work. Being as you mentioned a null reference exception it is highly likely a HTTP_REFERRER header wasn't set by the client, either because of a firewall, a proxy server, or some other filter or intermediary.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...