0

I am stored userid and password using cookie if user click on remember me checkbox on login view

 HttpCookie UserID = new HttpCookie("UserID");
 HttpCookie Password = new HttpCookie("Password");

 UserID.Value = vm.UserID;
 UserID.Expires = DateTime.Now.AddDays(30);
 Password.Value = vm.Password;
 Password.Expires = DateTime.Now.AddDays(30);

 Response.Cookies.Add(UserID);
 Response.Cookies.Add(Password);

I am clear browser cookie but it's remain as it is means when user open login view then userid and password fields are filled automatically. So where these cookies actually stored client side or server side? And how user clear these cookie if they want?

Parth Savadiya
  • 1,203
  • 3
  • 18
  • 40
  • Possible duplicate of [Delete cookie on clicking sign out](http://stackoverflow.com/questions/7079565/delete-cookie-on-clicking-sign-out) – Mathemats Mar 04 '16 at 05:23

2 Answers2

1

HttpCookie If you stored with time limit so It's share hard disk, but if you use non-persistent cookies for your application it is very useful and alive only time to browser open. When the user closes the browser, the cookie is discarded.

Use reference from https://msdn.microsoft.com/en-us/library/ms178194.aspx

0

The browser is responsible for managing cookies on a user system. Cookies are sent to the browser via the HttpResponse object that exposes a collection called Cookies. You can access the HttpResponse object as the Response property of your Page class. Any cookies that you want to send to the browser must be added to this collection. When creating a cookie, you specify a Name and Value. Each cookie must have a unique name so that it can be identified later when reading it from the browser. Because cookies are stored by name, naming two cookies the same will cause one to be overwritten.

You can add cookies to the Cookies collection in a number of ways.

Example

Response.Cookies["userName"].Value = "Tim";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

 HttpCookie aCookie = new HttpCookie("lastVisit");
 aCookie.Value = DateTime.Now.ToString();
 aCookie.Expires = DateTime.Now.AddDays(1);
 Response.Cookies.Add(aCookie);`

use Expires function and specify time

The cookie might be remaining because you are sending it from server side again

aCookie.Expires = DateTime.Now.AddMinutes(1.0);

This will remove that cookie after 1 minute from current time

   aCookie.Expires = DateTime.Now.AddDays(-1);

This will remove that cookie 1 day before ie, yesterday

DAre G
  • 177
  • 10