cookie から Browser Capabilities を取得する

クライアントの機能を判別する新しい方法が、IIS 5.0 に導入されました。クライアントの機能を記述した cookie が、要求の一部としてクライアントから送信されると、ASP ページは Browser Capabilities コンポーネントのインスタンスを作成して、cookie に指定されている名前と値のペアをプロパティとして追加します。

たとえば、userLanguage=Spanish という名前と値のペアを含んだ cookie がクライアントから送信されると、Browser Capabilities コンポーネントは userLanguage プロパティを追加し、そのプロパティの値を Spanish に設定します。

重要

Server.Transfer メソッドまたは Server.Execute メソッドを使用したリダイレクトの結果としてクライアントから要求されたファイル内に、METADATA# メタタグが存在する場合、IIS はそのメタタグを無視します。ただし、実際にリダイレクトを含んでいるファイル内の METADATA メタタグは通常どおりに処理されます。

次の例では、cookie を使用してブラウザの機能を判別します。この処理には 2 つのファイルが必要です。

--- SendCook.htm ---

<HTML>
<HEAD>

<SCRIPT language="JavaScript">

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

function window.onload ()
{
  oClientCaps.style.behavior = "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;
}
</SCRIPT>

</HEAD>

<BODY ID="oClientCaps">
</BODY>

</HTML>

--- CheckCap.asp ---

<!--METADATA TYPE="Cookie" NAME="BrowsCap" SRC="sendcook.htm"-->
<HTML>

<BODY>
<% 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>")
%>
</BODY>

</HTML>

ブラウザの機能を確認する場合の設計上の影響については、「クライアント機能」を参照してください。


© 1997-2001 Microsoft Corporation.All rights reserved.