프로그래밍 노트/ASP.NET
Cookie (쿠키)
무난킴
2014. 4. 25. 15:07
namespace Test_KMH { public partial class Ex_Cookie : System.Web.UI.Page { int tempCount = 0; protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["Count"] == null) { Response.Cookies["Count"].Value = "0"; SetCount(); } } protected void SetCount() { lbl_Text.Text = tempCount.ToString(); } protected void btn_Add_Click(object sender, EventArgs e) { tempCount = Convert.ToInt32(Request.Cookies["Count"].Value) + 1; Response.Cookies["Count"].Value = tempCount.ToString(); // 쿠키의 만료시간을 현재시간 이후 10초뒤로 설정 Response.Cookies["Count"].Expires = DateTime.Now.AddSeconds(10); SetCount(); } protected void btn_Del_Click(object sender, EventArgs e) { tempCount = Convert.ToInt32(Request.Cookies["Count"].Value) - 1; Response.Cookies["Count"].Value = tempCount.ToString(); Response.Cookies["Count"].Expires = DateTime.Now.AddSeconds(10); SetCount(); } } }