Mehraban
Mehraban

Reputation: 3324

How to check cookie existence in .net framework 2.0?

I've used this code to check if some cookie exists in request:

if (Request.Cookies.AllKeys.Contains("action")

But this code does not work in .net framework 2.0 since System.Array does not contain a definition for Contains. What is the most simple thing to do this other than iterating through AllKeys?

Upvotes: 0

Views: 149

Answers (1)

DGibbs
DGibbs

Reputation: 14618

You can check it on the Cookies collection itself by using the name as an index and avoid having to access AllKeys:

 if (Request.Cookies["action"] != null)

Upvotes: 2

Related Questions