Avia Afer
Avia Afer

Reputation: 866

can't delete cookies, nor find where are they stored

i am trying to learn how to handle cookies, it seems easy to understand the concept but as i need to check what happens if i try and read non existing one i could not find the cookie

i have done all these :

  1. deleted temporery asp.net files
  2. deleted cookies in ie9
  3. deleted the project and loaded via open - website.

class instance

public KwPosCookies.meta KwCookMet = new KwPosCookies.meta();

pageLoad.. : after the cookie was set i commented the creation of cookie.

    string getCookieDtail = "";
    //var x = KwCookMet.SetUsrCkie1(KwCookMet.cookieSName, "currUSName", "currUSMail");
    //Response.SetCookie(x);
    getCookieDtail = KwCookMet.GetUCkie1ValAsStr(KwCookMet.cookieSName, KwCookMet.usermail);

this is the class for cookies

public class KwPosCookies
{
    public class meta
    {
        public readonly string username = "UserName";
        public readonly string usermail = "UserEmail";
        public readonly string LastTimeVisit = "LTV";
        public readonly string cookieSName = "UserInfo1";
        public HttpCookie SetUsrCkie1(string CookieName, string Uname, string UMail)
        {
            var retC = new HttpCookie(CookieName);
            retC.Expires = DateTime.Now.AddMonths(1);
            retC[username] = Uname;
            retC[usermail] = UMail;
            retC[LastTimeVisit] = DateTime.Now.ToString("ddMMyyyy");

            return retC;
        }
        public string  GetUCkie1ValAsStr(string CookieName, string KeyToGet)
        {
            return HttpContext.Current.Request.Cookies[CookieName][KeyToGet];
        }

    }

}

still reading the cookie will show it is still there (somewhere) with same values.

Upvotes: 1

Views: 180

Answers (1)

Crab Bucket
Crab Bucket

Reputation: 6277

With your code I would

  1. check that the cookie key is definitely the same between request and response.
  2. ensure that the browser is configured to accept cookies.
  3. I would get and set the cookie in the same session i.e. use a button on the page to drop the cookie. If you are running the site through Visual Studios built in webserver rerunning the site will effectively be restarting the server. Also it could use a different port. I'm not convinced you would be able to see the dropped cookie in that circumstance

Generally

The way that I work out what is going on with cookies is just to watch them be created and destroyed using firefox or chrome. So in chrome with the developer toolbar (F12) go

Resources -> Cookie

enter image description here

and get the below screen. Honestly the best way I have found to work out what is going on.

Upvotes: 2

Related Questions