cookies question

W

William

I'm new to ASPX. In my .aspx page I set multiple cookies from the session
variables to the "visitor" container:


dim cookie as HttpCookie
cookie=new HttpCookie("visitor")
cookie.Values.Add("cid", Session("sid"))
cookie.Values.Add("ckeywords",Session("skeywords"))
cookie.Values.Add("ccampaignno",Session("scampaignno"))
cookie.Values.Add("cadgroup",Session("sadgroup"))
cookie.Expires = Now.AddDays(365)
response.appendcookie(cookie)


But I need to set those cookies only if they do not exist on the computer.
If I surround the code with if-then statement that looks like this:

If Request.Cookies("visitor") is Nothing Then

dim cookie ....
...
...
response.append ...

end if

the browser gives me an error.

My question is how do I check if the container "visitor" exists in cookies?

Thank you for your time.
 
W

William

Sorry -

Forgot to include the error:

If the cookies "visitor" do not exist the error is:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
 
J

Joerg Jooss

William said:
I'm new to ASPX. In my .aspx page I set multiple cookies from the
session variables to the "visitor" container:


dim cookie as HttpCookie
cookie=new HttpCookie("visitor")
cookie.Values.Add("cid", Session("sid"))
cookie.Values.Add("ckeywords",Session("skeywords"))
cookie.Values.Add("ccampaignno",Session("scampaignno"))
cookie.Values.Add("cadgroup",Session("sadgroup"))
cookie.Expires = Now.AddDays(365)
response.appendcookie(cookie)


But I need to set those cookies only if they do not exist on the
computer. If I surround the code with if-then statement that looks
like this:

If Request.Cookies("visitor") is Nothing Then

dim cookie ....
...
...
response.append ...

end if

the browser gives me an error.

My question is how do I check if the container "visitor" exists in
cookies?

That code is fine -- the error must be at a different line in your
code.

Note that is not a "browser error", but a simple coding error in your
code behind class, which you can easily debug...

Cheers,
 
Joined
Dec 27, 2007
Messages
1
Reaction score
0
You should use:

If Request.Cookies("visitor") is Null rather than
Request.Cookies("visitor") is Nothing
 

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

Cookie Question 1
Asp.net 2.0 - Cookies 2
Changing cookie values 0
Cookies 1
Cookies 1
Cookies 0
Cookie problem 1
Cookies will not expire (noob question) 4

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top