1

Is there a simple one-liner I can use to detect if the page request is coming from a Webkit browser? C# ASP.NET Framework 4.0

10
  • What's your motive for browser detection? Commented Jan 3, 2011 at 20:38
  • @sapph I need to programatically apply gradients to some HtmlControls. I can't add the background Style attr twice (one for FF and one for Chrome) so I need to detect the browser being used Commented Jan 3, 2011 at 20:43
  • I'd suggest just using both CSS properties in your style attribute. Sure, you are sending "useless" CSS to each browser, but I'd argue that it's easier to maintain (and more reliable) than peeking at the user agent. Commented Jan 3, 2011 at 20:49
  • @sapph I would but as far as I can tell, adding a second style attribute ('background') programmatically overwrites the previous one. So I can only have one. Commented Jan 3, 2011 at 20:54
  • @Berin what I'm saying is you can't add a second style with the same name twice programmatically. The second will overwrite the first. Commented Jan 3, 2011 at 21:12

1 Answer 1

2

You can use the HttpBrowserCapabilities. Here is an example.

 System.Web.HttpBrowserCapabilities browser = Request.Browser; string s = "Browser Capabilities\n" + "Type = " + browser.Type + "\n" + "Name = " + browser.Browser + "\n" + "Version = " + browser.Version + "\n" + "Major Version = " + browser.MajorVersion + "\n" + "Minor Version = " + browser.MinorVersion + "\n" + "Platform = " + browser.Platform + "\n" + "Is Beta = " + browser.Beta + "\n" + "Is Crawler = " + browser.Crawler + "\n" + "Is AOL = " + browser.AOL + "\n" + "Is Win16 = " + browser.Win16 + "\n" + "Is Win32 = " + browser.Win32 + "\n" + "Supports Frames = " + browser.Frames + "\n" + "Supports Tables = " + browser.Tables + "\n" + "Supports Cookies = " + browser.Cookies + "\n" + "Supports VBScript = " + browser.VBScript + "\n" + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "\n" + "Supports Java Applets = " + browser.JavaApplets + "\n" + "Supports ActiveX Controls = " + browser.ActiveXControls + "\n" + "Supports JavaScript Version = " + browser["JavaScriptVersion"] + "\n"; 

http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.