[ASP.NET, .NET웹강좌]닷넷쿠키사용예제(ASP.NET Cookie)
ASP.Net에서 쿠키를 생성하고, 읽고, 삭제하는 예제 입니다.
잘 활용하시기 바랍니다.
잘 활용하시기 바랍니다.
감사합니다.
<%@ Page Language="C#" %>
<script runat="server">
public void Button1_Click(object sender, EventArgs e)
{
HttpCookie name = new HttpCookie("name");
HttpCookie url = new HttpCookie("url");
HttpCookie lastVisit = new HttpCookie("last");
HttpCookie visitCount = new HttpCookie("visitCount");
<script runat="server">
public void Button1_Click(object sender, EventArgs e)
{
HttpCookie name = new HttpCookie("name");
HttpCookie url = new HttpCookie("url");
HttpCookie lastVisit = new HttpCookie("last");
HttpCookie visitCount = new HttpCookie("visitCount");
DateTime now = DateTime.Now;
name.Value = "오엔제이,오라클자바커뮤니티";
url.Value = "www.onjprogramming.co.kr";
lastVisit.Value = now.ToString();
visitCount.Value = "1";
url.Value = "www.onjprogramming.co.kr";
lastVisit.Value = now.ToString();
visitCount.Value = "1";
Response.Cookies.Add(name);
Response.Cookies.Add(url);
Response.Cookies.Add(lastVisit);
Response.Cookies.Add(visitCount);
Response.Cookies.Add(url);
Response.Cookies.Add(lastVisit);
Response.Cookies.Add(visitCount);
Response.Write("Cookie Setting OK~");
}
public void Button2_Click(object sender, EventArgs e)
{
if (Request.Cookies.Count > 0)
{
if (Request.Cookies["name"] != null)
{
label1.Text += "<br>name 쿠키 : " + Request.Cookies["name"].Value + "<br>";
}
}
public void Button2_Click(object sender, EventArgs e)
{
if (Request.Cookies.Count > 0)
{
if (Request.Cookies["name"] != null)
{
label1.Text += "<br>name 쿠키 : " + Request.Cookies["name"].Value + "<br>";
}
if (Request.Cookies["url"] != null)
{
label1.Text += "url 쿠키 : " + Request.Cookies["url"].Value + "<br>";
}
if (Request.Cookies["last"] != null)
{
label1.Text += "last 쿠키 : " + Request.Cookies["last"].Value + "<br><br>";
}
{
label1.Text += "url 쿠키 : " + Request.Cookies["url"].Value + "<br>";
}
if (Request.Cookies["last"] != null)
{
label1.Text += "last 쿠키 : " + Request.Cookies["last"].Value + "<br><br>";
}
int vCount = 0;
if (Request.Cookies["visitCount"] != null)
{
vCount = Convert.ToInt32(Request.Cookies["visitCount"].Value);
vCount++;
}
HttpCookie visitCount = new HttpCookie("visitCount");
visitCount.Value = vCount.ToString();
Response.Cookies.Add(visitCount);
if (Request.Cookies["visitCount"] != null)
{
vCount = Convert.ToInt32(Request.Cookies["visitCount"].Value);
vCount++;
}
HttpCookie visitCount = new HttpCookie("visitCount");
visitCount.Value = vCount.ToString();
Response.Cookies.Add(visitCount);
foreach (String str in Request.Cookies.AllKeys)
{
label1.Text += str + ":" + Request.Cookies[str].Value + "<br>";
}
}
}
public void Button3_Click(object sender, EventArgs e)
{
foreach (String str in Request.Cookies.AllKeys)
{
Response.Cookies[str].Expires = DateTime.Now.AddDays(-1);
}
{
label1.Text += str + ":" + Request.Cookies[str].Value + "<br>";
}
}
}
public void Button3_Click(object sender, EventArgs e)
{
foreach (String str in Request.Cookies.AllKeys)
{
Response.Cookies[str].Expires = DateTime.Now.AddDays(-1);
}
label1.Text = "쿠키 삭제 OK~";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="button1" onClick="Button1_Click" runat="server" Text="Cookie Setting" />
<asp:Button ID="button2" onClick="Button2_Click" runat="server" Text="Get Cookies" />
<asp:Button ID="button3" onClick="Button3_Click" runat="server" Text="Delete Cookies" />
<asp:Label ID="label1" runat="server" Text="" />
</form>
</body>
</html>
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="button1" onClick="Button1_Click" runat="server" Text="Cookie Setting" />
<asp:Button ID="button2" onClick="Button2_Click" runat="server" Text="Get Cookies" />
<asp:Button ID="button3" onClick="Button3_Click" runat="server" Text="Delete Cookies" />
<asp:Label ID="label1" runat="server" Text="" />
</form>
</body>
</html>
[개강확정강좌]오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)
[주간]
[11/4]Spring3.X, MyBatis, Hibernate실무과정
[11/6]SQL초보에서실전전문가까지
[평일야간]
[11/1]C#,ASP.NET마스터
[11/5]iPhone 하이브리드 앱 개발 실무과정
[11/7]JAVA&WEB프레임워크실무과정
[11/8]Spring3.X, MyBatis, Hibernate실무과정
[주말]
[11/9]C#,ASP.NET마스터
[11/9]JAVA&WEB프레임워크실무과정
[11/9]안드로이드개발자과정
[11/9]웹퍼블리싱 마스터
[11/9]Spring3.X, MyBatis, Hibernate실무과정
[주간]
[11/4]Spring3.X, MyBatis, Hibernate실무과정
[11/6]SQL초보에서실전전문가까지
[평일야간]
[11/1]C#,ASP.NET마스터
[11/5]iPhone 하이브리드 앱 개발 실무과정
[11/7]JAVA&WEB프레임워크실무과정
[11/8]Spring3.X, MyBatis, Hibernate실무과정
[주말]
[11/9]C#,ASP.NET마스터
[11/9]JAVA&WEB프레임워크실무과정
[11/9]안드로이드개발자과정
[11/9]웹퍼블리싱 마스터
[11/9]Spring3.X, MyBatis, Hibernate실무과정
댓글 없음:
댓글 쓰기