<%@ Import Namespace="System.Net" %>
protected void Page_Load(object sender, System.EventArgs e) {
HttpCookie cookie = new HttpCookie("ColorCookie");
cookie["Color"] = "Crimson";
cookie["ColorValue"] = "#DC143C";
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
Label1.Text = "Cookie created successfully and set expire after 1 year";
if (myCookie != null)
{
string color = myCookie["Color"];
string colorValue = myCookie["ColorValue"];
Label1.Text += "<br /><br />Cookie[ColorCookie] Found and read<br/>";
Label1.Text += "Color: " + color;
Label1.Text += "<br />Value: " + colorValue;
}
}
</script>
<head id="Head1" runat="server">
<title>asp.net cookie example: how to set expires date time</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Teal">asp.net Cookie example: set cookie expires</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="Crimson"
Font-Italic="true"
Font-Bold="true"
>
</asp:Label>
</div>
</form>
</body>
</html>
No comments:
Post a Comment