301跳转和"蜘蛛"检测


301跳转


   if (Request.Cookies["login"]==null)
   {
    Response.Status ="301 Moved Permanently";
    Response.AddHeader("Location",http://www.zongen.com);   }

"蜘蛛"检测

  public static bool IsSpider()
  {
   DataSet ds=new DataSet();
   ds.ReadXml(System.Web.HttpContext.Current.Server.MapPath("~/Spider.xml"));
   DataTable dt_xml=ds.Tables[0];
   for(int i=0;i<dt_xml.Rows.Count;i++)
   {
    if(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].IndexOf(dt_xml.Rows[i]["name"].ToString())!=-1)
    {
     return true;
    }
   }
   return false;
  }

如果返回true表示"蜘蛛"请求是由蜘蛛发出的
Spider.xml

<?xml version="1.0" encoding="utf-8" ?>
<Spiders>

<Spider>
<describe>有道-网易</describe>
<name>YodaoBot</name>
</Spider>

<Spider>
<describe>百度</describe>
<name>Baiduspider</name>
</Spider>

<Spider>
<describe>搜狗</describe>
<name>sogou spider</name>
</Spider>

<Spider>
<describe>雅虎中国1</describe>
<name>Yahoo! Slurp China</name>
</Spider>

<Spider>
<describe>雅虎1</describe>
<name>Yahoo! Slurp</name>
</Spider>

<Spider>
<describe>雅虎中国2</describe>
<name>Yahoo Slurp China</name>
</Spider>

<Spider>
<describe>雅虎2</describe>
<name>Yahoo Slurp</name>
</Spider>

<Spider>
<describe>雅虎3</describe>
<name>Slurp</name>
</Spider>

<Spider>
<describe>雅虎图片</describe>
<name>Yahoo-MMCrawler</name>
</Spider>

<Spider>
<describe>雅虎Blog</describe>
<name>Yahoo-Blogs/v3.9</name>
</Spider>

<Spider>
<describe>谷歌</describe>
<name>Googlebot</name>
</Spider>

<Spider>
<describe>谷歌图片</describe>
<name>Googlebot-Image</name>
</Spider>

<Spider>
<describe>谷歌adsense</describe>
<name>Mediapartners-Google</name>
</Spider>

<Spider>
<describe>谷歌adwords</describe>
<name>Adsbot-Google</name>
</Spider>

<Spider>
<describe>MSN</describe>
<name>msnbot</name>
</Spider>

<Spider>
<describe>Teoma</describe>
<name>Teoma</name>
</Spider>

<Spider>
<describe>搜搜</describe>
<name>Sosospider</name>
</Spider>

<Spider>
<describe>SCOOTER</describe>
<name>Scooter</name>
</Spider>

<Spider>
<describe>IA</describe>
<name>ia_archiver</name>
</Spider>

<Spider>
<describe>LYCOS</describe>
<name>Lycos_Spider_(T-Rex)</name>
</Spider>

<Spider>
<describe>FAST</describe>
<name>FAST-WebCrawler</name>
</Spider>

</Spiders>

posted @ 2008-03-20 18:53  yejun  阅读(1372)  评论(1编辑  收藏  举报