Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does anyone have any thoughts on how I can set persistence to true and
have the cookie retained to enable me not to have to login the next
time I visit the site?
Posted

You don't set a "persitence" property, you set an expiration date/time:

0) Create the cookie
1) Add the user's credentials
2) Set the expire time
3) Write the cookie to the client machine

C#
HttpCookie myCookie = new HttpCookie("myCookie");  
myCookie.Values.Add("userid", objUser.id.ToString());  
myCookie.Expires = DateTime.Now.AddDays(5);  
Response.Cookies.Add(myCookie); 


That's all there is to it.
 
Share this answer
 
Comments
haseebsvirgo 24-Mar-11 11:04am    
i have done that but when i closed my browser and then again open it i was automatically logged out.
Thats what i dont want to do.
Hey i think there is no any problem with the code, please check for the setting for cookie in browser, different browser have different interface for enabling/disabling cookie.

try once..
 
Share this answer
 

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