我们可以检测谷歌机器人抓取我的页面ASP.Net时

时间:2014-11-11 09:54:50

标签: asp.net bots googlebot

我需要以编程方式检测谷歌机器人或任何其他搜索引擎机器人何时抓取我们的网站页面。我在global.asax的Application_BeginRequest中有逻辑,当请求任何页面时,我尝试读取两个cookie值,如果有人丢失,那么我将用户重定向到用户选择国家/地区的特定页面cookie被丢弃在用户个人电脑中。

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    string strCountryCookie = BBAreman.CountryCookie.GetCookieValue();
    string strShippingCookie = BBAreman.CountryCookie.GetShippingCookieValue();

    if (Request.Url.ToString().IndexOf(".asmx") == -1)
    {
    if (strCountryCookie.Trim() == "" || strShippingCookie.Trim() == "")
    {
        if (Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/index.aspx?ShowCountry=true" != HttpContext.Current.Request.Url.ToString())
        {
        Response.Redirect("~/index.aspx?ShowCountry=true");
        }
    }
    }
}

现在当谷歌机器人访问我们的任何页面时,僵尸程序将重定向到特定页面,而无法访问任何页面。结果我们的网站失去了排名。

我从不面对这种情况。所以请各位指导我如何处理这种情况。感谢

修改

我有一个例行程序

If(Request.Browser.Crawler) Then
    'this is a web bot
Else
    'this is a regular user
End If

我想以上方式我可以检测到机器人正在爬行我的页面或任何人类?告诉我我是否在正确的轨道上?

解决

我这样解决了

public class Utility
{
public static bool IsCrawlByBot()
    {
        List<string> Crawlers = new List<string>()
        {
            "googlebot","bingbot","yandexbot","ahrefsbot","msnbot","linkedinbot","exabot","compspybot",
            "yesupbot","paperlibot","tweetmemebot","semrushbot","gigabot","voilabot","adsbot-google",
            "botlink","alkalinebot","araybot","undrip bot","borg-bot","boxseabot","yodaobot","admedia bot",
            "ezooms.bot","confuzzledbot","coolbot","internet cruiser robot","yolinkbot","diibot","musobot",
            "dragonbot","elfinbot","wikiobot","twitterbot","contextad bot","hambot","iajabot","news bot",
            "irobot","socialradarbot","ko_yappo_robot","skimbot","psbot","rixbot","seznambot","careerbot",
            "simbot","solbot","mail.ru_bot","spiderbot","blekkobot","bitlybot","techbot","void-bot",
            "vwbot_k","diffbot","friendfeedbot","archive.org_bot","woriobot","crystalsemanticsbot","wepbot",
            "spbot","tweetedtimes bot","mj12bot","who.is bot","psbot","robot","jbot","bbot","bot"
        };

        string ua = HttpContext.Current.Request.UserAgent.ToLower();
        bool iscrawler = Crawlers.Exists(x => ua.Contains(x));
        return iscrawler;
    }
}

protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            //if (!Request.Browser.Crawler)
            if (!Utility.IsCrawlByBot())
            {
                string strCountryCookie = BBAreman.CountryCookie.GetCookieValue();
                string strShippingCookie = BBAreman.CountryCookie.GetShippingCookieValue();
                if (Request.Url.ToString().IndexOf(".asmx") == -1)
                {
                    if (strCountryCookie.Trim() == "" || strShippingCookie.Trim() == "")
                    {
                        if (Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/index.aspx?ShowCountry=true" != HttpContext.Current.Request.Url.ToString())
                        {
                            Response.Redirect("~/index.aspx?ShowCountry=true");
                        }
                    }
                }
            }
        }

0 个答案:

没有答案