HttpListenerResponse.Cookies プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpListenerResponse.Cookies プロパティの意味・解説 

HttpListenerResponse.Cookies プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

応答と共に返される Cookieコレクション取得または設定します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Property Cookies As
 CookieCollection
Dim instance As HttpListenerResponse
Dim value As CookieCollection

value = instance.Cookies

instance.Cookies = value
public CookieCollection Cookies { get; set;
 }
public:
property CookieCollection^ Cookies {
    CookieCollection^ get ();
    void set (CookieCollection^ value);
}
/** @property */
public CookieCollection get_Cookies ()

/** @property */
public void set_Cookies (CookieCollection value)
public function get Cookies
 () : CookieCollection

public function set Cookies
 (value : CookieCollection)

プロパティ
応答付随している Cookie格納している CookieCollection。応答Cookie追加されていない場合、このコレクションは空です。

解説解説

Cookie は、ローカル (クライアント) コンピュータ格納されている、Web サーバーから取得された名前と値のテキスト データです。サポートされている Cookie形式は、NetscapeRFC 2109、および RFC 2965 です。Netscape Cookie仕様については、http://wp.netscape.com/newsref/std/cookie_spec.html を参照してくださいRFCドキュメントは、http://www.rfc-editor.org を参照してください

使用例使用例

要求Cookie確認し要求Cookieない場合応答と共に新しCookie返すコード例次に示します

// This example requires the System and System.Net namespaces.

public static string NextCustomerID()
{
    // A real-world application would do something more robust
    // to ensure uniqueness.
    return DateTime.Now.ToString();
}
public static void SimpleListenerCookieExample(string[]
 prefixes)
{
    // Create a listener.
    HttpListener listener = new HttpListener();
    // Add the prefixes.
    foreach (string s in
 prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.IgnoreWriteExceptions = true;
    listener.Start();
    Console.WriteLine("Listening...");
    // Note: The GetContext method blocks while waiting for a request.
 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    string customerID = null;

    // Did the request come with a cookie?
    Cookie cookie = request.Cookies["ID"];
    if (cookie != null)
    {
         customerID=cookie.Value;
    }
    if (customerID !=null)
    {
          Console.WriteLine("Found the cookie!");
    }
    // Get the response object.
    HttpListenerResponse response = context.Response;
    // If they didn't provide a cookie containing their ID, give them
 one.
    if (customerID == null)
    {
        customerID = NextCustomerID();
        Cookie cook = new Cookie("ID", customerID );
        response.AppendCookie (cook);
    }
    // Construct a response.
    string responseString = "<HTML><BODY> Hello
 " + customerID + "!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get the response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    output.Write(buffer,0,buffer.Length);
    // You must close the output stream.
    output.Close();
    // Closing the response sends the response to the client.
    response.Close();
    listener.Stop();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpListenerResponse クラス
HttpListenerResponse メンバ
System.Net 名前空間
HttpListener クラス
HttpListenerContext クラス
HttpListenerRequest クラス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpListenerResponse.Cookies プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpListenerResponse.Cookies プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS