HttpListenerResponse.SetCookie メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpListenerResponse.SetCookie メソッドの意味・解説 

HttpListenerResponse.SetCookie メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

この応答と共に送信された Cookie のコレクションに対して Cookie を追加または更新します。

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

例外例外
例外の種類条件

ArgumentNullException

cookie が null 参照 (Visual Basic では Nothing) です。

ArgumentException

Cookie が既にコレクション内に存在し、置き換えることができません。

解説解説

Name、Domain、および Path の各プロパティの値が同じ場合、2 つの Cookie は同じと見なされます。これらの 3 つの情報が同じ場合、このメソッドは Cookie を更新しようとします。名前とドメインの比較では大文字と小文字が区別されませんが、パスの比較では大文字と小文字が区別されます。

使用例使用例

メソッドの呼び出しについては、次のコード例を参照してください。

// This example requires the System and System.Net namespaces.
public static void SimpleCookieExample(string[]
 prefixes)
{
    // Create a listener.
    HttpListener listener = new HttpListener();
    // Add the prefixes.
    foreach (string s in
 prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    Console.WriteLine("Listening...");
    // Note: The GetContext method blocks while waiting for a request.
 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    
    // This application sends a cookie to the client marking the time
 
    // they visited. 
    Cookie timeStampCookie = new Cookie("VisitDate",
 DateTime.Now.ToString());
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Add the cookie to the response.
    response.SetCookie(timeStampCookie);
    // Construct a response.
    string responseString = "<HTML><BODY> Hello
 world!</BODY></HTML>";
    response.ContentEncoding = System.Text.Encoding.UTF8;
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Send the response.
    response.Close(buffer, true);
    listener.Stop();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpListenerResponse クラス
HttpListenerResponse メンバ
System.Net 名前空間
HttpListener クラス
HttpListenerContext クラス
HttpListenerRequest クラス



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

HttpListenerResponse.SetCookie メソッドのお隣キーワード

   

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



HttpListenerResponse.SetCookie メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS