Watch Out for Request.Browser.MajorVersion in ASP.NET 2.0

I awoke to 1500 exceptions published to me this morning from our public site running ASP.NET 2.0.  Not good times.  "Luckily" they were all the same: Value cannot be null.  It seems one of the components that we are using is calling Request.Browser.MajorVersion and blowing up on goofy user-agents.  In this case the user-agent of doom is "YahooSeeker/1.2 (compatible; Mozilla 4.0; MSIE 5.5; yahooseeker at yahoo-inc dot com ; http://help.yahoo.com/help/us/shop/merchant/)".  For whatever reason ASP.NET 2.0 cannot parse the MajorVersion out of that and tries to call int.Parse on a null value, causing an error.

Luckily we own the source code to this particular component, so I just wrapped the calls to MajorVersion in a try block so that the entire site doesn't blow up on bogus error codes, so hopefully if you run into that particular error you'll be able to track it down.  I haven't tried any of the other properties of the Browser class, but if you are relying on them for anything you might want to first test them out with a rediculous user agent and see what blows up. 

1 Comment

  • I believe this particular component was trying to figure out what "features" it was going to provide. For example, with IE it will use the DirectX filters to do some fancy animations.



    Personally, the closest I'll come to browser specific code will be using CSS hacks to work around IE's flaws.

Comments have been disabled for this content.