What is the proper way to use cookies?

E

Eric Layman

This is how I clear all cookies/give cookies/detect cookies

am i doing it the right way?
Somehow or rather, i would hit an object cannot be instanisiated from null
or something whenever it tries to read cookies


Clear cookies:
Response.Cookies.Clear()

Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If Not ck1 Is Nothing Then

Response.Cookies("USERLOGGEDIN").Expires = DateTime.Now.AddDays(-1)

End If





This is how I put in cookies:

If Request.Cookies("USERLOGGEDIN") Is Nothing Then

Dim ck As New HttpCookie("USERLOGGEDIN")

ck.Value = "1"

Response.Cookies.Add(ck)

End If



This is how i detect cookies:



Dim ck1 As HttpCookie = Request.Cookies("USERLOGGEDIN")

If ck1 Is Nothing Then

Response.Redirect("login.aspx")

End If
 
A

Alvin Bruney [MVP]

Code seems ok to me at first glance. Do you have a stack trace of the error?

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
 

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

Similar Threads

Clearing cookies 2
Cookies C# 3
Cookies Count 2
Cookies? 0
Cookies 1
What's the proper way of reading cookies? Request.Cookies("mycook") doesnt work 3
Cookies during error handling 1
Cookies 7

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top