For the user agent string
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)
HttpContext.Current.Request.Browser.MajorVersion
returns 3
and HttpContext.Current.Request.Browser.MinorVersion
returns 5
. So far so good.
However for this user agent string (seen in the wild by one of my users)
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 (CK-Finbu.com) Firefox/3.6 (.NET CLR 3.5.30729)
HttpContext.Current.Request.Browser.MajorVersion
returns 1
and HttpContext.Current.Request.Browser.MinorVersion
returns 9
. It 开发者_如何学JAVAlooks like ASP.NET has picked up the numbers from the CVS tag info rather than the browser version.
Does this mean that ASP.NET's user agent parsing is broken?
Seems you'll need to tweak your mozilla.browser
file (in %windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers\
folder).
Around line 188, you'll see this (regex to match Firefox browser):
"Gecko\/\d+ Firefox\/(?'version'(?'major'\d+)(?'minor'\.[.\d]*))"
Should be
"Gecko\/\d+(?: \S+)? Firefox\/(?'version'(?'major'\d+)(?'minor'\.[.\d]*))"
精彩评论