How can I determine where a user came from when they land on my webpage.
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.
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.
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.
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.
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.
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).
Look at the HTTP Referrer header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With