cookie

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);

}
 
L

Lars-Erik Aabech

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
 
J

John Toop

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);
}
 
H

Hans Kesting

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
 
T

Tom

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top