Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am trying to change the value of the cookie when the LOGOUT button is pressed like this...
Request.Cookies["LoginInfo"].Value=null;

or
Request.Cookies["LoginInfo"].Value="0";

I am unable to change the value of cookie...
is there any way to change the value at any time...
plz help...
Posted
Updated 29-Mar-11 10:54am
v2

 
Share this answer
 
Comments
AspDotNetDev 29-Mar-11 23:56pm    
A practical article that goes into good detail about cookies without getting too abstract or technical. Your answer doesn't cover the OP's specific issue, but that's ok since mine already does. 5.
Hello,

You can try something like

C#
Response.Cookies["LoginInfo"].Value = "0";
 
Share this answer
 
v2
Comments
AspDotNetDev 29-Mar-11 20:57pm    
FYI, that's part of what I said.
Bryian Tan 29-Mar-11 21:54pm    
oops, sorry you are right, I was focusing on the highlighted section.
Perhaps you need to set the expiration of the cookie to be in the future. Also, set the response, not the request:
C#
Response.Cookies["LoginInfo"].Expires = DateTime.Now.AddDays(1);


http://msdn.microsoft.com/en-us/library/ms178194.aspx (ASP.NET Cookies Overview)
 
Share this answer
 
Comments
Venkatesh Mookkan 29-Mar-11 22:18pm    
You are changing the Cookie Expiration here. How this help the OP to fix his issue?

It should be Response.Cookies["LoginInfo"].Value = 0.

But you the gave the idea about Response object at lease.
AspDotNetDev 29-Mar-11 23:52pm    
Did you notice the part where I said "also, set the response, not the request"? And I wasn't sure what happens when the cookie expiration is not set (does it expire right away, is it infinite?), so I recommended the OP explicitly set that as well, as that couldn't hurt.
Venkatesh Mookkan 29-Mar-11 23:55pm    
The OP is using LoginInfo value for checking the validity of the Cookie. So, expiration doesn't make sense in his case.
AspDotNetDev 29-Mar-11 23:53pm    
From the article Chris Maunder posted a link to in an alternate answer: "If you just set a cookie's value then it will create a cookie with Expires set to DateTime.MinValue (01-Jan-0001 00:00)".
Venkatesh Mookkan 29-Mar-11 23:55pm    
The OP is using LoginInfo value for checking the validity of the Cookie. So, expiration doesn't make sense in his case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900