0

I have some code that logs certain clicks, etc on our site.

It seems that the link of the url is being followed by google and giving us false button click audits.

I'm just wondering if there is a good way in c# to check the user-agent to see if it is a search engine.

This is obviously quite a common thing but I'm not finding anything obvious on google!

STLDev
  • 5,950
  • 25
  • 36
Simon
  • 1,966
  • 5
  • 21
  • 35

1 Answers1

0

In ASP.NET, the User-Agent header is available via HttpRequest.UserAgent.

String userAgent;
userAgent = Request.UserAgent;
if (userAgent.IndexOf("MSIE 6.0") > -1) 
{
   // The browser is Microsoft Internet Explorer Version 6.0.
}

You can modify the string it's checking for to be whatever Google Bot's user-agent is.

Curtis Rutland
  • 776
  • 4
  • 12
  • *Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.* - http://stackoverflow.com/help/how-to-answer – Ant P Apr 29 '14 at 21:18
  • 1
    Was editing it in as you made the comment, hit submit before I was done. – Curtis Rutland Apr 29 '14 at 21:20
  • Thanks I think this probably was a duplicate, the link to the duplicate gave an exact answer... – Simon Apr 29 '14 at 21:37