Reputation: 6769
If I have a domain which is:
(1) http://www.myownsite.com
And I have another domain that has a link to it:
(2) http://www.pointingtomyownsite.com
Is there a way to find out whether (1) is opened through a redirect from (2) in ASP.NET MVC?
Upvotes: 0
Views: 326
Reputation: 3928
It depends on what you mean by "redirect". If you mean a CNAME DNS entry (where one hostname appears in the browser even though the page is served from another host, and which many people incorrectly call a DNS redirect), then Senad's answer is correct, Request.Url.Host will work. (This is not a redirect BTW).
A real redirect will change the hostname shown in the browser window, and you can get the URL of the previous page using HttpRequest.UrlReferrer. This works for both redirects and links. Although the Referer HTTP header this property exposes is not technically required and may be NULL, in practice it will be sent by all the browsers you should care about except for possibly if the URL was entered directly on a new tab.
Upvotes: 2
Reputation: 13756
Yes,
var hostname = requestContext.HttpContext.Request.Url.Host
Upvotes: 0