cookie

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

cookie question

I've added the following to page_load in asp.net

but no cookie were set when I checked browser.. anyone know why ? or did I
miss something ?

Thanks



if (Request.Browser.Cookies)

{

HttpCookie cook = new HttpCookie("cookie_Tom");

cook.Value = "my cookie vale";

Response.Cookies.Add(cook);

}
 
I put a button on a page and wrote the following code in Page_Load.. Works
for me:

if (!IsPostBack)
{
if (Request.Browser.Cookies)
{
Response.Cookies.Add(new HttpCookie("a_cookie", "The cookie"));
}
}
else
{
if (Request.Browser.Cookies)
{
Response.Write(Request.Cookies["a_cookie"].Value);
}
}

What do you mean by "checked browser"?

L-E
 
Hi Tom,
What's the intent of your "if (Request.Browser.Cookies)" ? Do you think that
possibly the condition is preventing the cookie from being set?

This is the code that I always cut and paste (for what it's worth)

private void SaveCookie(string cookieName, string cookieValue)
{
System.Web.HttpCookie cookieUsr = new
System.Web.HttpCookie(cookieName,cookieValue);
DateTime dtNow = DateTime.Now;
// give us 90 days from today till this cookie expires
TimeSpan tsExpires = new TimeSpan(89,23,59,59);
cookieUsr.Expires = dtNow.Add(tsExpires);
Response.Cookies.Add(cookieUsr);
}
 
Tom said:
cookie question

I've added the following to page_load in asp.net

but no cookie were set when I checked browser.. anyone know why ? or
did I miss something ?

Thanks

Did you look in "Temporary Internet Files" for a stored cookie-file? When you
don't have an expirydate set for the cookie, it is treated as "temporary"
(to be forgotten as soon as the browser closes). The cookie might not
be written to the filesystem then. Try adding an expirydate (in the future).

Hans Kesting
 
I don't know why but I can't see cookies in exploer but I can see it in
trace

how do you guys check it ?
 
Back
Top