title: Why am I getting these strange results when looking at browser capabilities?
body: <p>I am currently looking into browser capabilities and am trying to test the browser definition files that come with .NET 4.0. To do this I am using an add-on for Firefox to change the user agent and I have a simple page which reports on the following:</p>
  
  <pre><code>Request.UserAgent
  Request.Browser.Id
  Request.Browser.Browser
  Request.Browser.MajorVersion
  Request.Browser.MinorVersion
  Request.Browser.Platform
  Request.Browser.IsMobileDevice
  Request.Browser.MobileDeviceManufacturer
  Request.Browser.MobileDeviceModel
  </code></pre>
  
  <p>Generally this gives the correct information based on the examples provided in the comments in the default browser definition files. However I am seeing strange results from time to time that I cannot quite explain.</p>
  
  <p>Take the example iPhone user agent in the <code>iphone.browser</code> definition file which is as follows:</p>
  
  <pre><code>Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3
  </code></pre>
  
  <p>This should return the browser as Safari, which it does. This is down to the IPhone gateway having Safari as a parent, which matches on the term <code>Safari</code>.</p>
  
  <p>Altering the user agent slightly so it emulates the user agent of the mail client on an iPhone means removing the end part of the user agent as follows:</p>
  
  <pre><code>Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko)
  </code></pre>
  
  <p>This now should return Mozilla as the browser, as it will be unable to match on the term <code>Safari</code>. However, analysing this immediately after the first reports back incorrect information, and still indicates the browser to be Safari.</p>
  
  <p>Adding a custom <code>.browser</code> file with the <code>App_Browsers</code> folder and then modifying that seems to force it to be correct temporarily, almost like the definitions or rules are being cached and not fully run on each request.</p>
  
  <p>This works the other way too, if you start with the second example user agent then upon analysing the first it will report as being Mozilla instead of Safari.</p>
  
  <p>Can anyone explain this behaviour or a way to work around it? Is it trying to do some sort of (not so) clever caching where it makes assumptions based on similar user agents?</p>
  
  <p>Thanks.</p>