URL of referring/calling page

  • Thread starter Thread starter Zeba
  • Start date Start date
Z

Zeba

Hi !

How do I get the URL of the page which has called the current page.
Say PageA.aspx calls PageB.aspx. How do I get PageA's url from the
Pre_Init function of PageB. I tried something like

Request.UrlReferrer.ToString()

But it gives me an Object not instantiated error.

Same with Request.ServerControls[HTTP_REFERER]

How can I get the previous page url ? Please help soon !

Thanks !
 
Zeba said:
How do I get the URL of the page which has called the current page.
Say PageA.aspx calls PageB.aspx. How do I get PageA's url from the
Pre_Init function of PageB. I tried something like

Request.UrlReferrer.ToString()

But it gives me an Object not instantiated error.

Hi,
The simple test shows that the task with the conditions you discribed
(PageA.aspx calls PageB.aspx) always returns Request.UrlReferrer!=null
and it cannot generate the "Object not instantiated" error.
So I guess the problem is in something you did not mention.
There are 2 cases when it can happens:
1. You calls PageB.aspx by the means of JavaScript:
<a href="javascript:window.open('PageB.aspx');void(0);"...
In this case try to change link:
<a href="PageB.aspx" target="_blank" ...

2. PageA.aspx is a secure page. (https://...../PageA.aspx). Honestly,
I am not sure you can get information about PageA.aspx anyway.
 
Hi,
My PageB is not called through javascript. PageA is not secure either.
So what could be the reason for the error ? This statement is given in
the pre-init function. Could that be the reason ?
Thanks!
 
Zeba said:
Hi,
My PageB is not called through javascript. PageA is not secure either.
So what could be the reason for the error ?

I don't know. Type of UrlReferrer is Uri. It creates based on the url
of PageA.aspx. But there are a lot of cases when it can not be
created. Look here for UriFormatException:
http://msdn2.microsoft.com/en-us/library/ceyeze4f.aspx
I am not sure, it is only idea.
This statement is given in
the pre-init function. Could that be the reason ?

Replace the code to Page_Load and test.

Regards.
 
Noting there are several ways to defeat the use of the HTTP_REFERER variable
it can be used reliably on one's own site but does require a click event to
populate the variable with data. So don't call. Click :-)

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
 

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

Back
Top