C#中如何判断是否来自搜索引擎链接 - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Jun 15

C#中如何判断是否来自搜索引擎链接 不指定

tommyhu , 23:02 , ASP.NET , Comments(0) , Trackbacks(0) , Reads(8803) , Via Original Large | Medium | Small
判断访问来源是不是搜索引擎的爬虫
判断访问链接是否从搜索引擎过来,网上摘录的,欢迎提供更多方法!可以给我邮件admin@tommyhu.cn,3q!

/// 判断是否来自搜索引擎链接
/// 是否来自搜索引擎链接
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;
}
相关代码:
<%
'检查当前用户是否是蜘蛛人
Function check(user_agent)
    allow_agent=split("Baiduspider,Scooter,ia_archiver,Googlebot,FAST-WebCrawler,MSNBOT,Slurp",",")
    check_agent=false
    For agenti=lbound(allow_agent) to ubound(allow_agent)
        If instr(user_agent,allow_agent(agenti))>0 then
            check_agent=true
            exit for
        end if
    Next
    check=check_agent
End function
user_agent=Request.ServerVariables("HTTP_USER_AGENT")
if check(user_agent)=False then Response.Write(" <meta http-equiv=refresh content=""0;URL=index.html"">")
%>
▲返回顶部
Last modified by tommyhu on2011/06/16 23:07

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot