Reputation: 34218
last time i was in situation where i need to detect bot and i solved this way.
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");
}
}
}
}
}
now i am in situation where i need to know my web site is accessing by a application other than any browser. i could develop a routine which will return many browser name but the problem is i know only few browser majorly used from pc. how to get all popular or not popular browser user agent name may be used from pc, any device or mobile. if i get it then my job will be easier to log report only when my web site would be accessed by application other than browser.
Upvotes: 0
Views: 508
Reputation: 21
First google link. But it requires java.
http://uadetector.sourceforge.net
Upvotes: 1
Reputation: 21
You could check if html/text is supported.
if(Request.Browser.PreferredRenderingMime == "text/html")
{
Response.Write("This is an HTML device.");
}
Upvotes: 1