Lazycoder

12Nov/051

Don’t sniff for browser versions

Request.Browser.Version may not be a double: “Avoid writing code like this to do browser detection:

if(Double.Parse(Request.Browser.Version) < 5.2) { // 5 or less

(Via ComputerZen.com – Scott Hanselman.)

I’ll second the call to not use Request.Browser.Version, but for a different reason. Checking for a specific browser version leads to the land of never-ending if-elses. You should always sniff for browser functionality unless you have damn good reason to pick a single browser version. Usually when I’m preaching that, it’s during a client-side scripting presentation. But it applies to server-side sniffing as well. If you want to find out of a browser supports ActiveX, check Request.Browser.ActiveXControls rather than checking using an “isIE” var.

Filed under: General Leave a comment
  • http://www.msmvps.com/WilliamRyan Bill

    Yikes, I wasn’t hip to this, I have some code to change