My application needs to store cookies. When a user logs on I want to make sure that if the cookie does not exist create it and store value, but if it does modify it.
if(cookieExist)
{
cookiename = "value";
}
else
{
create a new cookie
then store the value;
}
Thanks for any help
You have to use Request.Cookies
to get cookie value and Response.Cookies
to add cookies
string cookievalue ;
if ( Request.Cookies["cookie"] != null )
{
cookievalue = Request.Cookies["cookie"].ToString();
}
else
{
Response.Cookies["cookie"].Value = "cookie value";
Response.Cookies["cookie"].Expires = DateTime.Now.AddMinutes(1); // add expiry time
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With