how set cookies enable and disable and time in mvc application [Resolved]

Posted by Kishore22 under ASP.NET MVC on 1/14/2014 | Points: 10 | Views : 1331 | Status : [Member] | Replies : 5
how set cookies enable and disable and time in mvc application




Responses

Posted by: Kmandapalli on: 1/15/2014 [Member] Silver | Points: 50

Up
0
Down

Resolved
Hi,

You can perform in this way,

var cookie = new HttpCookie("cookieName");

cookie.Value = "value";
Response.Cookies.Add(cookie);

//remove cookie
var cookie = new HttpCookie("cookieName");
cookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(cookie);

//To Request the cookies value
var val = Request.Cookies["cookieName"].Value;

Mark as answer if satisfied...

Regards,
Shree M.

Kavya Shree Mandapalli

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kishore22 on: 1/15/2014 [Member] Starter | Points: 25

Up
0
Down
how to set time for cookies..??

where we have to mention the above code in controller or any other

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kmandapalli on: 1/15/2014 [Member] Silver | Points: 25

Up
0
Down
Hi,

You have to write all this stuff in the controller.
To set the cookie expiry time,
MyCookie.Expires = DateTime.Now.AddMinutes(10.0);

Mark as answer if satisfied.....


Regards,
Shree M.


Kavya Shree Mandapalli

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kishore22 on: 1/15/2014 [Member] Starter | Points: 25

Up
0
Down
Thanku shree

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kmandapalli on: 1/15/2014 [Member] Silver | Points: 25

Up
0
Down
Hi,

Can you please mark it as answer...

Regards,
Shree M.

Kavya Shree Mandapalli

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response