2012-04-24 19 views
1

在我的asp.net MVC應用程序,我試圖知道這是誰是調用我的網站之一的Facebook(當我的網站鏈接共享爲一個FB狀態和FB試圖爲opengraph獲取一些元標記)。我嘗試了URlReferrer,它是空的,並且UserHostName顯示IP地址。試圖檢測到我的網絡應用程序的調用facebook

+1

您可以嘗試DNS查找IP地址嗎? – Tejs 2012-04-24 19:02:38

回答

0

你可以做的TEJS建議,是這樣的:

IPHostEntry IpEntry = Dns.GetHostByAddress(HttpContext.Current.Request.UserHostAddress); 
//OR 
IPHostEntry IpEntry = Dns.GetHostByAddress(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]); 
if(IpEntry.HostName.Contains("facebook.com")) 
{ 
    //Coming from facebook.com 
} 
0

看起來這可以像這樣做:

if ((!string.IsNullOrWhiteSpace(HttpContext.Request.UserAgent) && HttpContext.Request.UserAgent.ToLower().Contains("facebookexternalhit")) || 
    ((HttpContext.Request.UrlReferrer != null) && HttpContext.Request.UrlReferrer.Host.ToLower().Contains("facebook.com"))) 

這樣,我知道如果Facebook被抓住opengraph數據,或者如果有人點擊Facebook頁面上的共享鏈接。

相關問題