Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > cookies question

Reply
Thread Tools

cookies question

 
 
William
Guest
Posts: n/a
 
      06-03-2005
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("scampaign no"))
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.


 
Reply With Quote
 
 
 
 
William
Guest
Posts: n/a
 
      06-03-2005
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" <(E-Mail Removed)> wrote in message
news:Cc1oe.1605$(E-Mail Removed)...
> 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("scampaign no"))
> 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.
>
>



 
Reply With Quote
 
 
 
 
Joerg Jooss
Guest
Posts: n/a
 
      06-03-2005
William wrote:

> 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("scampaign no"))
> 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,
--
http://www.joergjooss.de
(E-Mail Removed)
 
Reply With Quote
 
harafat harafat is offline
Junior Member
Join Date: Dec 2007
Posts: 1
 
      12-27-2007
You should use:

If Request.Cookies("visitor") is Null rather than
Request.Cookies("visitor") is Nothing
 
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
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
What's the proper way of reading cookies? Request.Cookies("mycook") doesnt work user ASP .Net 3 03-31-2007 01:53 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM
Good Cookies bad Cookies? AK Computer Support 23 10-26-2003 05:20 AM



Advertisments