Checking to see if a cookie exists

C

CES

I'm sorry for the 101 question but I can't seem to get this to work... I'm
tiring to test if a cookie has been created before.

Everything I've seen indicates that Request.Cookies works the same in .net
as it did in old asp but for some reason I'm getting
"System.NullReferenceException: Object reference not set to an instance of
an object" when ever I attempt to test for the cookie . It doesn't return an
error if the cookie exists but does if it isn't there.

<%@ Page Explicit="TRUE" Language="vb" Debug="true"%>
<%
Dim cookie1 As string
cookie1 = Request.Cookies("testCookie")
%>

I've found lots of references on reading a cookie as long as you know it
there but I can't seem to find one that will test if it exists. I'm new to
..net from old asp and I'm totally lost, Any help on this would be
appreciated.
CES
 
G

Guest

You can always use Request.Browser.Cookies to see if cookie support exists for that browser.

The other option is to look to see if there are any cookies passed in first by using
if (Request.Cookies.Count > 0) {
// your cookie acces
 
N

.NET Follower

hi,
if Request.Cookies["name"]!-null
then only access yhe value..
error is coz
there may be no key value corresponding to the name u hv specified..

so there is no refernce to look for...
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top