Updated on Kisan Patel
This tutorial will explain you how to set DateTime when the cookie should expire in ASP.NET.
Default.aspx
<asp:Button ID="btnCookieSet" runat="server" Text="Set Cookie with Expire DateTime" OnClick="SetCookie" />
Default.aspx.cs
protected void SetCookie(object sender, EventArgs e) { // set the cookie Response.Cookies["MyCookie"].Value = "My cookie data"; Response.Cookies["MyCookie"].Expires = DateTime.Now.AddSeconds(5); }