Cookieの書き込み

ただ書き込む場合

this.HttpContext.Response.Cookies.Append("TestKey1", "TestValue1");
this.HttpContext.Response.Cookies.Append("TestKey2", "TestValue2");

Cookiesの詳細オプション設定して書き込み

  • このオプションを設定すると「samesite=lax」が追加される
    • この属性があるとクロスドメインアクセスしたときに当該Cookieを送信しなくなる
var cOptions = new CookieOptions() {
    HttpOnly = true,
    Expires = new DateTimeOffset(DateTime.Now.AddDays(2))
};
this.HttpContext.Response.Cookies.Append(cKey,cValue,cOptions);

Cookieの読み込み

  • 方法1
    string cValue = this.HttpContext.Request.Cookies[cKey];
  • 方法2
    string cookie = this.HttpContext.Request.Headers["Cookie"];

Cookieの削除

this.HttpContext.Response.Cookies.Delete(cKey);

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-05-23 (水) 15:02:55 (2163d)