Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I determine where the user came from in asp.net?

How can I determine where a user came from when they land on my webpage.

  • Did they come from a google link?
  • Did they user a favorites link?
  • Did they type in the url?
like image 663
user279521 Avatar asked Jul 02 '10 13:07

user279521


People also ask

How do I find out which page a user came from?

To check if the user came from a specific website or by clicking a link to your website, you can use the referrer property in the global document object.

How does ViewData work?

ViewData is used to pass the data from the controller action method to a view and we can display this data on the view. The ViewData is work on the principle of Key-value pairs. This type of binding is known as loosely binding.

What does return View() in MVC do?

This process determines which view file is used based on the view name. The default behavior of the View method ( return View(); ) is to return a view with the same name as the action method from which it's called.

How authorization works in ASP.NET Core?

ASP.NET Core authorization provides a simple, declarative role and a rich policy-based model. Authorization is expressed in requirements, and handlers evaluate a user's claims against requirements.


3 Answers

If the user browsed to your site via a hyperlink, the following will provide this information:

Request.ServerVariables["HTTP_REFERER"]

Although note on the above it is possible for browsers to block the value (empty value).

You also won't be able to detect if the user specifically used a favorite, typed in the link, etc. These are browser actions that are outside the scope of what client or serverside code can detect once the user lands on your site.

like image 184
KP. Avatar answered Sep 30 '22 01:09

KP.


You can check the Request.UrlReferrer of the current HttpRequest: it will usually contain the page from where the user is coming from (depends on the browser, though).

If the URI contains "google.com/search" you can assume it is a google search and can try to extract the keywords used (you might want to use a regex to detect all various google regional domains). If it is empty, the user probably typed in your URL (or used a favorite link).

like image 40
LorenzCK Avatar answered Sep 30 '22 03:09

LorenzCK


Look at the HTTP Referrer header.

like image 27
leppie Avatar answered Sep 30 '22 03:09

leppie