request cookie from class


In my helper class, i want to request the GUID cookie:
public class help
    public string Guid()
        string Guid = HttpContext.Current.Request.Cookies.AllKeys.Contains("Guid") ? HttpContext.Current.Request.Cookies["Guid"].Value : string.Empty;

But i get this error:
Error 1 'System.Array' does not contain a definition for 'Contains' and it found no extension method' Contains' accepting a first argument of type 'System.Array' (you're missing a 'using' directive or a assemblyreference?)

Can anybody help?

The error is in this string:
Jesper ChristensenProgrammerAsked:
Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Do you have using System.Linq at the top of your class file? Contains is an extension method for arrays.
This is because "AllKeys" is of type System.Array which does not contain a method of "Contains". You need to check some other way like "IndexOf()"

string Guid = HttpContext.Current.Request.Cookies.AllKeys.IndexOf("Guid") > -1 ? HttpContext.Current.Request.Cookies["Guid"].Value : string.Empty;

Open in new window

kaufmed's solution should work as well. It is a matter of preference.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

käµfm³d 👽Commented:
kaufmed's solution should work as well.
...provided you're targeting .NET Framework 3.0 or greater   ; )
"...provided you're targeting .NET Framework 3.0 or greater   ; )"

Chances are the posted pulled this code from an existing file and moved it into a class for easy re-use. So my guess is the original file already had the using statement and is therefore 3.0+
Jesper ChristensenProgrammerAuthor Commented:
Thanks guys
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.