Sponsored by Gluten Free Waffles and Sliced Bananas

Wednesday, June 23, 2010

Detect Google Chrome Browser with ASP.NET

6:28 AM Posted by Tyson Nero 2 comments
Can't detect Chrome by default with ASP.NET? Here's the quick way.

  1. Right-click you project and select Add ASP.NET Folder > App_Browsers
  2. Right-click App_Browsers and select Add New Item > Browser File. Name it Chrome.browser.
  3. Add the following code to Chrome.browser.


Increase the number of characters ASP.NET uses for the user agent header in Web.config:



You can now create a file to test browser detection. Here is some code to get you through the process.

.aspx page:





Code behind:
lblBrowser.Text = Request.Browser.Type + ", " + Request.Browser.Platform;

lblData.Text = "User Agent = " + Request.UserAgent + " ";
lblData.Text += "Type = " + Request.Browser.Type + " ";
lblData.Text += "Name = " + Request.Browser.Browser + " ";
lblData.Text += "Version = " + Request.Browser.Version + " ";
lblData.Text += "Major Version = " + Request.Browser.MajorVersion + " ";
lblData.Text += "Minor Version = " + Request.Browser.MinorVersion + " ";
lblData.Text += "Platform = " + Request.Browser.Platform + " ";
lblData.Text += "Is Beta = " + Request.Browser.Beta + " ";
lblData.Text += "Is Crawler = " + Request.Browser.Crawler + " ";
lblData.Text += "Is AOL = " + Request.Browser.AOL + " ";
lblData.Text += "Is Win16 = " + Request.Browser.Win16 + " ";
lblData.Text += "Is Win32 = " + Request.Browser.Win32 + " ";
lblData.Text += "Supports Frames = " + Request.Browser.Frames + " ";
lblData.Text += "Supports Tables = " + Request.Browser.Tables + " ";
lblData.Text += "Supports Cookies = " + Request.Browser.Cookies + " ";
lblData.Text += "Supports VB Script = " + Request.Browser.VBScript + " ";
lblData.Text += "Supports JavaScript = " + Request.Browser.JavaScript + " ";
lblData.Text += "Supports Java Applets = " + Request.Browser.JavaApplets + " ";
lblData.Text += "CDF = " + Request.Browser.CDF + " ";