You are currently offline, waiting for your internet to reconnect

How To Determine Browser Type in Server-Side Script Without the BrowserType Object

This article was previously published under Q272413
There are two common methods in server-side script to determine information about the browser that is being used by the client:
  • The BrowserType object
  • The Request.ServerVariables("HTTP_USER_AGENT") method
This article describes the Request.ServerVariables("HTTP_USER_AGENT") method, which provides more detailed information about the browser than the BrowserType object. For additional information about the BrowserType object (as well as the use of client-side script to obtain browser information), click the article number below to view the article in the Microsoft Knowledge Base:
167820 How To Determine Browser Version from a Script
IMPORTANT: The methods that are used in this article rely on the Web site receiving the correct "HTTP_USER_AGENT" string for browsers that connect to the site. Some proxy servers and browsers may send information that is incorrect or difficult to interpret. For example, the default HTTP_USER_AGENT string that Opera 5.12 returns is "Mozilla/4.0 (compatible; MSIE 5.0; <operating system>) Opera 5.12 [en]". This string is hard to interpret because the first portion of the string is the same as the string that Internet Explorer 5 returns.

If you need to uniquely identify Internet Explorer version 5 or later (on Microsoft Win32 and Unix platforms only), use the isComponentInstalled or getComponentVersion methods of the CLIENTCAPS behavior. For information about these methods, see the following Microsoft Web sites:NOTE: These methods will fail if the client is not Internet Explorer 5 or later (Microsoft Win32 and Unix platforms only).
The following sample code illustrates the use of Request.ServerVariables("HTTP_USER_AGENT"):
<%   dim UserAgent	   UserAgent = Request.ServerVariables("HTTP_USER_AGENT")   Response.Write "<p>" & UserAgent & "</p>"	   if instr(1,UserAgent,"MSIE") > 0 then      Response.Write "Browser is Internet Explorer"   else      if instr(1,UserAgent,"MSPIE") > 0 then         Response.Write "Browser is Pocket Internet Explorer"      else         Response.Write "Browser is not Internet Explorer"      end if   end if%>				
In Microsoft Internet Explorer 5.0, this code returns the following data or similar:
Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt) Browser is Internet Explorer				
This sample code uses the string that is returned for Internet Explorer, but there is no standard format for the string that a browser returns to the HTTP_USER_AGENT server variable. The complete list of possible values for HTTP_USER_AGENT is quite long, and new values are added each time that a browser is updated.

Here is a very brief sample of HTTP_USER_AGENT values:
   Internet Explorer     - Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)     - Mozilla/4.0 (compatible; MSIE 4.0 Crawler; Windows 95)   Netscape Navigator     - Mozilla/4.0b1 (Win95; I)     - Mozilla/3.01Gold (Macintosh; U; PPC)				
To see samples of possible strings, search on your hard disk for a file named Browscap.ini, and open it in NotePad. Browscap.ini contains a list of values for Internet Explorer and Netscape Navigator, as well as browsers from Oracle and Opera. You can also download the most recent version of Browscap.ini from the following cyScape Web site: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.
detect verify check server.CreateObject("mswc.browsertype")

Article ID: 272413 - Last Review: 08/09/2007 06:22:06 - Revision: 1.5

  • Microsoft Visual InterDev 6.0 Standard Edition
  • Microsoft Active Server Pages 4.0
  • kbaspobj kbcodesnippet kbhowto KB272413