[thelist] ASP.NET Cookie Validation

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Mon Feb 10 13:04:01 CST 2003


>This may sound fairly simple but I want to check for the existance of a
>cookie
><snip/>
>But both times I get "System.NullReferenceException: Object reference not
>set to an instance of an object."

They both throw an exception because you are saying, "For the cookie named
'crmid', give me the value of its 'HasKeys' or 'Value' property." Except
that, if the cookie doesn't exist, there is no HttpCookie instance to
reference, therefore you get the NullReferenceException.

The SDK has a source code example, just load up your SDK docs and in the
Index type in "HttpRequest.Cookies" then hit <Enter>.

You might try something like this:

	If Not Request.Cookies.Item ( "crmid" ) Is Nothing
		...
	End If

Maybe that will work. The above tests to see if Request.Cookies.Item (
"crmid" ) is a valid reference to an instantiated HttpCookie object.

I haven't tested the code above though, if it fails maybe we need to do
something else.

-dave



More information about the thelist mailing list