Reputation: 263
How to get previous page url?
senario, user might come form google, yahoo, bing.
how to know where they come from?
i try using Request.UrlReferrer
but it returns a null value.
thanks for advice.
I am using ASP.NET webform, C#.
Update
I have a website running.
I just want to know that from where do they come from when the user visited my website.
Upvotes: 6
Views: 13026
Reputation: 155726
What you're describing is the Referer
HTTP header (originally a misspelling of "Referrer" that we're now stuck with). Browsers populate this field with the URI of any webpage that caused a user to navigate to a new page (such as by clicking an <a>
hyperlink, a <form
> submission, an action in a Flash object, etc). Not every user action will cause the header to be set, such as if an address is typed directly into the address bar, or if a link is opened in a desktop email messages.
Under ASP.NET this header is accessible by the Request.UrlReferrer
property. However this property will be null if the HTTP header value is not a URI or if the field was not set by the client UA.
You must never depend on this mechanism because it is set by the client, and you must never trust the client ( http://en.wikipedia.org/wiki/Defensive_programming ). And as stated, not all visitors will have the Referer header set.
Upvotes: 9