Bot Problem
URL: https://stackoverflow.com/questions/26862030/can-we-detect-when-google-bot-crawl-my-page-asp-net
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");
Comments
Post a Comment