cookies question

  • Thread starter Thread starter William
  • Start date Start date
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.
 
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.
 
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,
 
Back
Top