Get url

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I get the url of the web page that called my page? This may be from
a different web app and different web page. I explored the
page.previouspage, but it only seems to work if in the same application and
even then it doesn't give me the full url. Thank you for your help.
 
How can I get the url of the web page that called my page? This may be from
a different web app and different web page. I explored the
page.previouspage, but it only seems to work if in the same application and
even then it doesn't give me the full url. Thank you for your help.

You mean where user came from?

Try Request.UrlReferrer
 
Be aware, though, that you can't rely on this, as more and more ISPs are
stripping HTTP_REFERER from headers...

Mark is right, you have to check if (Request.UrlReferrer != null), for
example:

if (Request.UrlReferrer==null) {
// user typed in an URL directly, or used a bookmark
} else {
// user came from other website
}
 
Actually, from my "vast" experience
do not use Request.UrlReferrer
instead use Request.ServerVariables["HTTP_REFERER"]

the reason is that UrlReferrer is returning object Uri and it will throw
exception if passed referrer is in incorrect format.
So either be ready that code
if (Request.UrlReferrer != null)
can throw exception or use Request.ServerVariables["HTTP_REFERER"].
It always returns string and usually you do not need to know if it's a valid
http reference or not.
You should check for null anyway.


George.
 
Back
Top