A while back, I decided I needed to add browser-specific capabilities to my web application. While there are those who advocate using capability testing rather than browser sniffing, there is at least one good reason to prefer sniffing. That is that you want to be sure your site works as well as possible in all browsers but you want to take advantage of capabilities only available in some.
Thankfully, most web server technologies support browser sniffing, and ASP.NET has expanded on and improved on this with their control adapters in 2.0. But you can still use the old browser capabilities approach. To do this in 2.0, you simply add the special App_Browsers folder to your web site or project (if you're using WAP). In there you just add a file with the .browser extension, and you can put in your own custom browser capabilities there. Here's an example:
That's it, if all you want to do is extend the existing browser definitions. If you want to define new ones or to find out more about the browser schema, you can consult the MSDN docs. Using refID just lets you reference an existing definition and extend it. You can view existing definitions that ship with .NET in the Framework CONFIG\Browsers directory (e.g., C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers), but be sure not to modify those directly to avoid your customizations being overwritten with later patches.
Note: You might be tempted to set a default value using refID="Default" as the docs suggest, but I've confirmed that there is a bug that causes the default to actually overwrite the more specific settings. Microsoft tells me that they have scheduled a fix for this bug and that it will be released with the next Service Pack, but if you need it sooner, you can create a support incident and get a hotfix. So the workaround is to not use Default and have your code check against null to determine default. It's not the nicest approach, especially when you're using a Boolean value that would be better to just parse to bool, but it's not a travesty either.
You can then test for the capability in your code like so:
and do your downgrading if need be. Of course, if you have some serious alternative rendering that needs to occur, you should consider using control adapters (especially the PageAdapter) to avoid complicating code with lots of conditional statements.
The opinions expressed herein are solely my own personal opinions, founded or unfounded, rational or not, and you can quote me on that.
Thanks to the good folks at dasBlog!
Copyright © 2017 J. Ambrose Little