简体   繁体   中英

HttpCapabilitiesBase.Type Property - reliability

Accroding to MSDN , HttpCapabilitiesBase.Type property:

Gets the name and major (integer) version number of the browser.

For example, if the client is using Chrome version 36.0.1985.143, then
Request.Browser.Type == "Chrome36"

Now, how reliable is this info?

  • Which browsers does it support?
  • Are browsers displayed accurately?

Note: Users tampering with their request is no worry here.

The short answer is "not very", but depending on what you need, that might not be a concern for you.

HttpCapabilitiesBase works by matching the browser's User-Agent string against the browser information that the .NET Framework ships with. This information is stored in a collection of .browser files. Depending on which platform and .NET Framework version you are using, you can find the files at:

C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\CONFIG\\Browsers C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\CONFIG\\Browsers C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Config\\Browsers C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\Config\\Browsers

Microsoft updates these files infrequently via service packs, hotfixes or with new releases , but these updates aren't particularly frequent. As such, an update is only needed when an existing browser changes it's user-agent string, or a new browser with a new user-agent is launched. While this happens quite infrequently in the desktop browser world, it's a much bigger issue in the mobile browser world.

The .browser support for mobile browsers has frequently been found lagging . If proper detection of mobile browsers and their capabilities is important to you, then you will need to use a third-party device database.

The ASP.net Mobile website links to 51Degree's Foundation project which maintains a frequently updated device capability database . Note that there are free, as well as commercial versions available, with differing capabilities .

A similar option is the WURFL device repository, which also has free and commercial licenses available.

Alternatively, if you just want to maintain support for a very small subset of known browsers that aren't supported out of the box in .net, you can implement and use your own BrowserCapabilitiesProvider as shown in this answer by user Doug Domeny . I would not recommend this if you have a large set of browsers to support though. That way lies madness.:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM