Get url

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.
 
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.

You mean where user came from?

Try Request.UrlReferrer
 
G

Guest

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
}
 
G

George Ter-Saakov

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.
 

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

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top