Asp.net 2.0 - Cookies

  • Thread starter Thread starter Gil Paz
  • Start date Start date
G

Gil Paz

Looks like a very simple question, but I don't find the answer.
I use ASP.net 2.0 VB, I would like to check if a cookie exist on the clients
computer's and if not to create.

In order to create a cookie I write:

Dim Cookie As HttpCookie = New HttpCookie("UserID")
Cookie.Values.Add("SessionID", Session.SessionID)
Cookie.Expires = DateTime.Now.AddYears(30)
Response.Cookies.Add(Cookie)

But I don't know how to in the begining if the cookie exist or not.
Please, I need you help !
 
// Use the Request object to determine the status of the cookie
if (Request.Cookies["cookieName"] != null)
// do something
else
// create the cookie
 
Gil Paz said:
Looks like a very simple question, but I don't find the answer.
I use ASP.net 2.0 VB, I would like to check if a cookie exist on the clients
computer's and if not to create.

In order to create a cookie I write:

Dim Cookie As HttpCookie = New HttpCookie("UserID")
Cookie.Values.Add("SessionID", Session.SessionID)
Cookie.Expires = DateTime.Now.AddYears(30)
Response.Cookies.Add(Cookie)

But I don't know how to in the begining if the cookie exist or not.
Please, I need you help !

If Request.Cookies("UserID") Is Nothing
 
Back
Top