- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2017-12-11T02:10:35+00:00","default:admin","admin")
#author("2018-05-23T06:02:55+00:00","default:admin","admin")
-[[ASP.NET Core 2.0 MVC で Cookie を利用する:https://qiita.com/code0327/items/26c09c83103083ae57b7]]
*Cookieの書き込み [#pc1827b7]
**ただ書き込む場合 [#i2ccb9fe]
this.HttpContext.Response.Cookies.Append("TestKey1", "TestValue1");
this.HttpContext.Response.Cookies.Append("TestKey2", "TestValue2");
**Cookiesの詳細オプション設定して書き込み [#c79056b8]
-このオプションを設定すると「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の読み込み [#y5ed6f8e]
-方法1
string cValue = this.HttpContext.Request.Cookies[cKey];
-方法2
string cookie = this.HttpContext.Request.Headers["Cookie"];
**Cookieの削除 [#od255224]
this.HttpContext.Response.Cookies.Delete(cKey);