Retrieving Browser Capabilities from a Cookie

A new way of determining client capabilities was added in IIS 5.0. If the client sends a cookie describing their capabilities as part of the request, your ASP page can create an instance of the Browser Capabilities component that adds the name value pairs specified by the cookie as properties.

For example, if the client sent a cookie that contained a name-value pair of userLanguage=Spanish, the Browser Capabilities component would add a userLanguage property and set the value for this property to Spanish.

Important   If the METADATA#metatag exists in a file that is requested by the client as a result of a redirection using the Server.Transfer or Server.Execute methods, the metatag will be ignored by IIS. METADATA metatags in the file that actually contains the redirect, however, will be processed normally.

The following example demonstrates using a cookie to determine browser capabilities. Two files are required:


<SCRIPT language="JavaScript">

function stopAllErrors() 
   // No errors should be presented to the user if they occur.   
  return true;
window.onerror = stopAllErrors; 

function window.onload ()
{ = "url(#default#clientCaps)";
  bcString   =  "width= "          + oClientCaps.width;
  bcString  +=  "&height= "        + oClientCaps.height;
  bcString  +=  "&bufferDepth= "   + oClientCaps.bufferDepth;
  bcString  +=  "&colorDepth= "    + oClientCaps.colorDepth;
  bcString  +=  "&cookies= "       + oClientCaps.cookieEnabled;
  bcString  +=  "&platform= "      + oClientCaps.platform;
  document.cookie = "BrowsCap= "   + bcString;
<BODY ID="oClientCaps">

<!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="sendcook.htm"-->
<% Set myBrowsCap = Server.CreateObject("MSWC.BrowserType") %>
  Response.write("width= "        +myBrowsCap.width            + "<BR>")
  Response.write("height= "       +myBrowsCap.height           + "<BR>")
  Response.write("bufferDepth= "  +myBrowsCap.bufferDepth      + "<BR>")
  Response.write("colorDepth= "   +myBrowsCap.colorDepth       + "<BR>")
  Response.write("cookies= "      +CStr(myBrowsCap.cookies)    + "<BR>")
  Response.write("platform= "     +myBrowsCap.platform         + "<BR>")

For more information on the design implications for determining browser capabilities, see Client Capabilities.

© 1997-1999 Microsoft Corporation. All rights reserved.