Persistent or Permanent cookies

78
Views
2
Answers

How to set a persistent or permanent cookies in c#?

edit | flag
William Patrick
Asked on: Jun 16, 2011 at 5:18AM

2 Answers

5
2
5

If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser or if the session times out, the cookie is discarded. A non-persistent cookie like this is handy for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
To set a permanent(for a long time) cookie... try this..
Response.Cookies("userName").Value = "permanent"
Response.Cookies("userName").Expires = DateTime.Now.AddYears(1);// or the no of years you need

edit | flag
Gokul A
Answered on: Jun 16, 2011 at 7:33PM
6
1
6

If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser or if the session times out, the cookie is discarded. A non-persistent cookie like this is handy for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk.
To set a permanent(for a long time) cookie... try this..

Response.Cookies("userName").Value = "permanent"
Response.Cookies("userName").Expires = DateTime.Now.AddYears(1);// or the no of years you need
edit | flag
Gokul A
Answered on: Jun 16, 2011 at 7:33PM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags