what event to create cookie when leaving a page?

R

Rich

Hello,

I want to create a cookie that will expire in a few
mintues after a user leaves my page so that they can
return without having to login again if they were only
gone for a few minutes. I tried putting this code in the
Page_Unload event but got an error message that cookies
not supported here.
....
Sub Page_Unload 'this not working here
Dim objCookie As HttpCookie
objCookie = New HttpCookie("mycookie", "cookie1")
objCookie.expires = DateTime.Now.AddMinutes(2)
Response.Cookies.Add( objCookie )
End Sub
</script>

What is the best place to create a cookie that will only
last for a few mintues after leaving a page

Thanks,
Rich
 
S

Sylvain Lafontaine

Hi,

Don't know exactly for ASP.NET but in ASP, cookies must be written
before anything else HTML coding. With the Page_Unload event, I'm assuming
that all of your HTML page has been written to the client and made visible
to him. Obviously, it's way too late to write cookie at this time on the
server side when the page has been made visible to client side.

Also, with ASP and probably ASP.NET, the web server give you access to a
Session state, wich is probably a better choice for doing what you want than
trying to work out your own time-out cookies.

S. L.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top