ASPチュートリアル

ASPホーム

WPチュートリアル

Webページの紹介 WebPages Razor Webページのレイアウト Webページフォルダ WebPages Global Webページフォーム Webページオブジェクト Webページファイル Webページデータベース Webページヘルパー WebPages WebGrid Webページチャート Webページの電子メール Webページのセキュリティ Webページの公開 Webページの例 Webページクラス

ASP.NET Razor

かみそりのイントロ かみそりの構文 Razor C#変数 Razor C#ループ Razor C#ロジック RazorVB変数 かみそりVBループ RazorVBロジック

ASPクラシック

ASPイントロ ASP構文 ASP変数 ASP手順 ASP条件文 ASPループ ASPフォーム ASPCookie ASPセッション ASPアプリケーション ASP #include ASP Global.asa ASP AJAX ASPメール ASPの例

ASPリファレンス

ASPVB関数 ASPVBキーワード ASP応答 ASPリクエスト ASPアプリケーション ASPセッション ASPサーバー ASPエラー ASPファイルシステム ASP TextStream ASPドライブ ASPファイル ASPフォルダー ASP辞書 ASP AdRotator ASP BrowserCap ASPコンテンツリンク ASPコンテンツローテーター ASPクイック参照

ADOチュートリアル

ADOイントロ ADOコネクト ADOレコードセット ADOディスプレイ ADOクエリ ADOソート ADO追加 ADOアップデート ADO削除 ADO Demo ADOスピードアップ

ADOオブジェクト

ADOコマンド ADO接続 ADOエラー ADOフィールド ADOパラメータ ADOプロパティ ADOレコード ADOレコードセット ADOストリーム ADOデータ型

ASPCookiesコレクション_


❮完全な応答オブジェクトリファレンス

Cookiesコレクションは、Cookie値を設定または取得するために使用されます。Cookieが存在しない場合は作成され、指定された値を取得します。

注: Response.Cookiesコマンドは、<html>タグの前に表示する必要があります。

構文

Response.Cookies(name)[(key)|.attribute]=value

variablename=Request.Cookies(name)[(key)|.attribute]

Parameter Description
name Required. The name of the cookie
value Required for the Response.Cookies command. The value of the cookie
attribute Optional. Specifies information about the cookie. Can be one of the following parameters: 
  • Domain -  Write-only. The cookie is sent only to requests to this domain
  • Expires - Write-only. The date when the cookie expires. If no date is specified, the cookie will expire when the session ends
  • HasKeys - Read-only. Specifies whether the cookie has keys (This is the only attribute that can be used with the Request.Cookies command)
  • Path - Write-only. If set, the cookie is sent only to requests to this path. If not set, the application path is used
  • Secure - Write-only. Indicates if the cookie is secure
key Optional. Specifies the key to where the value is assigned

「Response.Cookies」コマンドは、Cookieを作成するため、またはCookieの値を設定するために使用されます。

<%
Response.Cookies("firstname")="Alex"
%>

上記のコードでは、「firstname」という名前のCookieを作成し、それに値「Alex」を割り当てています。

Cookieの有効期限が切れる日付を設定するなど、Cookieにいくつかの属性を割り当てることもできます。

<%
Response.Cookies("firstname")="Alex" 
Response.Cookies("firstname").Expires=#May 10,2002#
%>

これで、「firstname」という名前のCookieの値は「Alex」になり、2002年5月10日にユーザーのコンピューターから期限切れになります。

「Request.Cookies」コマンドは、Cookie値を取得するために使用されます。

以下の例では、Cookie「firstname」の値を取得してページに表示します。

<%
fname=Request.Cookies("firstname")
response.write("Firstname=" & fname)
%>

出力:
Firstname=Alex

Cookieには、複数の値のコレクションを含めることもできます。クッキーにはキーがあると言います。

以下の例では、「user」という名前のCookieコレクションを作成します。「ユーザー」Cookieには、ユーザーに関する情報を含むキーがあります。

<%
Response.Cookies("user")("firstname")="John"
Response.Cookies("user")("lastname")="Smith"
Response.Cookies("user")("country")="Norway"
Response.Cookies("user")("age")="25"
%>

以下のコードは、サーバーがユーザーに送信したすべてのCookieを読み取ります。コードは、CookieにHasKeysプロパティを持つキーがあるかどうかをチェックすることに注意してください。

<html>
<body>

<%
dim x,y

for each x in Request.Cookies
  response.write("<p>")
  if Request.Cookies(x).HasKeys then
    for each y in Request.Cookies(x)
      response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
      response.write("<br>")
    next
  else
    Response.Write(x & "=" & Request.Cookies(x) & "<br>")
  end if
  response.write "</p>"
next
%>

</body>
</html>
%>

出力:

firstname=Alex

user:firstname=John
user:lastname=Smith
user:
country=Norway
user:
age=25


❮完全な応答オブジェクトリファレンス