Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > what event to create cookie when leaving a page?

Reply
Thread Tools

what event to create cookie when leaving a page?

 
 
Rich
Guest
Posts: n/a
 
      02-20-2004
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
 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      02-21-2004
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.

"Rich" <(E-Mail Removed)> wrote in message
news:13e9101c3f7fc$7aa74e30$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing event user leaving page Zvonko Javascript 8 09-10-2005 09:19 AM
Raise event when leaving Textbox tshad ASP .Net 2 02-04-2005 12:10 AM
response.cookie in session_onstart event and IE 6.0 cookie acceptance wannaknow@yutzyz.com ASP General 0 06-22-2004 11:28 PM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM
Create cookie in what event when leaving page? Rich ASP .Net 1 02-20-2004 11:13 PM



Advertisments