Create cookie in what event when leaving page?

  • Thread starter Thread starter Rich
  • Start date Start date
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 in aspx, where
this is supported, that will only last for a few mintues
after leaving a page

Thanks,
Rich
 
page_unload fires after the page has been rendered, do it in page_load

-- bruce (sqlwork.com)
 
Back
Top