473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Checking to see if a cookie exists

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
Nov 18 '05 #1
2 2005
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

Nov 18 '05 #2
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...

--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"CES" <no**@none.com> wrote in message
news:OR*************@TK2MSFTNGP12.phx.gbl...
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.586 / Virus Database: 371 - Release Date: 2/12/2004
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shannon Jacobs | last post by:
I'm doing some trivial surveys, and I want to know if the same user answers twice. Can't really know that, but at least I thought I could check for the same browser/computer combination by using a...
2
by: Drummond | last post by:
I have set up two pages. The first writes a cookie and the second checks for its exsistence. If you follow the link to http://www.gadnet.com/test1.htm?test it will write a cookie named gadmcookie....
0
by: Lucifer | last post by:
Hi I have some code for checking for cookies, that sets a cookie on page1 and checks for it on page2. and its based on the code by MS: ...
4
by: Ziggy | last post by:
The purpose of my application is to require a website visitor to complete a form before participating in a search application. I have a specific reason for doing this with client-side javascript,...
3
by: Ben Amada | last post by:
Every time a user visits a particular page, I'm using the code below to add a cookie that expires in 1 day. My question is, a user may visit this page a few times within one day. Before adding...
4
by: Joe | last post by:
Hi, I have a asp.net page that checks if any one of the two cookies exists. If none of the cookies exist then redirect the user to login page. Cookie “try” doesn’t exists. I can see that...
2
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in...
2
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/>...
2
by: =?Utf-8?B?R2FpbFM=?= | last post by:
I tried to post this last week, but never saw it, so I hope it's not a duplicate. (Sorry if it is.) I am rewriting our member log-in page in classic ASP from PHP. We will be switching platforms...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.