C#判断访谒来源是否为搜索引擎链接的要领

时间:2022-04-19 07:28:25

这段代码通过获取UrlReferrer判断访客是否来自常用的搜索引擎,不是完全准确,,可做参考

/// 判断是否来自搜索引擎链接 /// 是否来自搜索引擎链接 public static bool IsSearchEnginesGet() { if (HttpContext.Current.Request.UrlReferrer == null) { return false; } string[] SearchEngine = { "google", "yahoo", "msn", "baidu", "sogou", "sohu", "sina", "163", "lycos", "tom", "yisou", "iask", "soso", "gougou", "zhongsou","bing" }; string tmpReferrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLower(); for (int i = 0; i < SearchEngine.Length; i++) { if (tmpReferrer.IndexOf(SearchEngine[i]) >= 0) { return true; } } return false; }