Reputation: 866
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 :
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
Reputation: 6277
With your code I would
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
and get the below screen. Honestly the best way I have found to work out what is going on.
Upvotes: 2