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
- What's your motive for browser detection?Sapph– Sapph2011-01-03 20:38:12 +00:00Commented 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 usedErix– Erix2011-01-03 20:43:01 +00:00Commented 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.Sapph– Sapph2011-01-03 20:49:48 +00:00Commented 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.Erix– Erix2011-01-03 20:54:07 +00:00Commented 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.Erix– Erix2011-01-03 21:12:30 +00:00Commented Jan 3, 2011 at 21:12
| Show 5 more comments
1 Answer
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";