HTTP_cookieとは? わかりやすく解説

HttpCookie クラス

HTTP cookie のそれぞれタイプ セーフ方法作成および操作できるようにします。

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

Public NotInheritable Class
 HttpCookie
public sealed class HttpCookie
public final class HttpCookie
解説解説
使用例使用例

HttpRequest オブジェクト内の DateCookieExample という名前の Cookie確認する方法次のコード例示します。この Cookie は、見つからない場合には作成されHttpResponse オブジェクト追加されます。この Cookie有効期限10 分に設定されています。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Page_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs)
        Dim sb As New StringBuilder()
        ' Get cookie from current request.
        Dim cookie As HttpCookie
        cookie = Request.Cookies.Get("DateCookieExample")
        
        ' Check if cookie exists in the current request
        If (cookie Is Nothing)
 Then
            sb.Append("Cookie was not received from the client.
 ")
            sb.Append("Creating cookie to add to the response.
 <br/>")
            ' Create cookie.
            cookie = New HttpCookie("DateCookieExample")
            ' Set value of cookie to current date time.
            cookie.Value = DateTime.Now.ToString()
            ' Set cookie to expire in 10 minutes.
            cookie.Expires = DateTime.Now.AddMinutes(10D)
            ' Insert the cookie in the current HttpResponse.
            Response.Cookies.Add(cookie)
        Else
            sb.Append("Cookie retrieved from client. <br/>")
            sb.Append("Cookie Name: " + cookie.Name
 + "<br/>")
            sb.Append("Cookie Value: " + cookie.Value
 + "<br/>")
            sb.Append("Cookie Expiration Date: " &
 _
                cookie.Expires.ToString() & "<br/>")
        End If
        Label1.Text = sb.ToString()

    End Sub
</script>

<html  >
<head runat="server">
    <title>HttpCookie Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label id="Label1" runat="server"></asp:Label>
    
    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender,
 EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        // Get cookie from the current request.
        HttpCookie cookie = Request.Cookies.Get("DateCookieExample");
        
        // Check if cookie exists in the current request.
        if (cookie == null)
        {
            sb.Append("Cookie was not received from the client. ");
            sb.Append("Creating cookie to add to the response. <br/>");
            // Create cookie.
            cookie = new HttpCookie("DateCookieExample");
            // Set value of cookie to current date time.
            cookie.Value = DateTime.Now.ToString();
            // Set cookie to expire in 10 minutes.
            cookie.Expires = DateTime.Now.AddMinutes(10d);
            // Insert the cookie in the current HttpResponse.
            Response.Cookies.Add(cookie);
        }
        else
        {
            sb.Append("Cookie retrieved from client. <br/>");
            sb.Append("Cookie Name: " + cookie.Name + "<br/>");
            sb.Append("Cookie Value: " + cookie.Value + "<br/>");
            sb.Append("Cookie Expiration Date: " + 
                cookie.Expires.ToString() + "<br/>");
        }
        Label1.Text = sb.ToString();
    }
</script>

<html  >
<head runat="server">
    <title>HttpCookie Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label id="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.Web.HttpCookie
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpCookie メンバ
System.Web 名前空間
HttpResponse
HttpRequest
HttpCookieCollection

HttpCookie コンストラクタ (String)


HttpCookie コンストラクタ

HttpCookie クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
HttpCookie (String) 新しcookie作成し、名前を付けます
HttpCookie (String, String) 新しcookie作成し、名前を付け、値を割り当てます
参照参照

関連項目

HttpCookie クラス
HttpCookie メンバ
System.Web 名前空間

HttpCookie コンストラクタ (String, String)

新しcookie作成し、名前を付け、値を割り当てます

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

使用例使用例

新しCookie作成し、名前を付け、値を設定するコード例次に示します

Dim MyCookie As New HttpCookie("LastVisit",
 CStr(DateTime.Now()))
    
HttpCookie MyCookie = new HttpCookie("LastVisit", 
    DateTime.Now.ToString());
    
HttpCookie myCookie = 
    new HttpCookie("LastVisit", DateTime.get_Now().ToString());
var myCookie : HttpCookie = new HttpCookie("LastVisit",
 String(DateTime.Now))
    
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

HttpCookie プロパティ


HttpCookie メソッド


HttpCookie メンバ

HTTP cookie のそれぞれタイプ セーフ方法作成および操作できるようにします。

HttpCookie データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

HttpCookie クラス
System.Web 名前空間
HttpResponse
HttpRequest
HttpCookieCollection


このページでは「.NET Framework クラス ライブラリ リファレンス」からHTTP_cookieを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHTTP_cookieを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHTTP_cookieを検索

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

辞書ショートカット

すべての辞書の索引

「HTTP_cookie」の関連用語

HTTP_cookieのお隣キーワード
検索ランキング

   

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



HTTP_cookieのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS