Microsoft KB Archive/272413

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

Article ID: 272413

Article Last Modified on 8/9/2007

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition
 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q272413



SUMMARY
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(&quot;HTTP_USER_AGENT&quot;) method

This article describes the Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;) 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 &quot;HTTP_USER_AGENT&quot; 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 &quot;Mozilla/4.0 (compatible; MSIE 5.0; ) Opera 5.12 [en]&quot;. 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:

http://msdn2.microsoft.com/en-us/library/ms531357.aspx

http://msdn2.microsoft.com/en-us/library/ms531350.aspx

NOTE: These methods will fail if the client is not Internet Explorer 5 or later (Microsoft Win32 and Unix platforms only).



MORE INFORMATION
The following sample code illustrates the use of Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;): <%  dim UserAgent UserAgent = Request.ServerVariables(&quot;HTTP_USER_AGENT&quot;) Response.Write &quot; &quot; & UserAgent & &quot; &quot; if instr(1,UserAgent,&quot;MSIE&quot;) > 0 then Response.Write &quot;Browser is Internet Explorer&quot; else if instr(1,UserAgent,&quot;MSPIE&quot;) > 0 then Response.Write &quot;Browser is Pocket Internet Explorer&quot; else Response.Write &quot;Browser is not Internet Explorer&quot; 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:

http://www.cyscape.com/asp/browscap

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.

Additional query words: detect verify check server.CreateObject(&quot;mswc.browsertype&quot;)

Keywords: kbaspobj kbcodesnippet kbhowto KB272413

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.