前田稔(Maeda Minoru)の超初心者のプログラム入門
void Button1_Click(object sender, EventArgs e) { // クッキーで LastVisit を設定する領域を定義 HttpCookie MyCookie = new HttpCookie("LastVisit"); // 現在時刻を取得 DateTime now = DateTime.Now; // LastVisit に現在時刻を設定 MyCookie.Value = now.ToString(); // 破棄時間を1時間後に設定 MyCookie.Expires = now.AddHours(1); // クッキーを登録 Response.Cookies.Add(MyCookie); } |
void Button2_Click(object sender, EventArgs e) { // クッキーで TestStr を設定する領域を定義 HttpCookie MyCookie = new HttpCookie("TestStr"); // TestStr に値をを設定 MyCookie.Value = "StringKey"; // 破棄時間を最大に設定 MyCookie.Expires = DateTime.MaxValue; // クッキーを登録 Response.Cookies.Add(MyCookie); } |