Thursday 15 September 2011

asp.net - How to detect that web site visitor is not using any browser -



asp.net - How to detect that web site visitor is not using any browser -

last time in situation need observe bot , solved 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)); homecoming 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 in situation need know web site accessing application other browser. develop routine homecoming many browser name problem know few browser majorly used pc. how popular or not popular browser user agent name may used pc, device or mobile. if job easier log study when web site accessed application other browser.

you check if html/text supported.

if(request.browser.preferredrenderingmime == "text/html") { response.write("this html device."); }

http://msdn.microsoft.com/ru-ru/library/system.web.configuration.httpcapabilitiesbase.preferredrenderingmime%28v=vs.110%29.aspx

asp.net browser web-crawler bots

No comments:

Post a Comment