request cookie from class

Hi.

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:
HttpContext.Current.Request.Cookies.AllKeys.Contains("Guid")
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.
0
 
strickddCommented:
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()"

http://msdn.microsoft.com/en-us/library/system.array.aspx

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

Open in new window

0
 
strickddCommented:
kaufmed's solution should work as well. It is a matter of preference.
0
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   ; )
0
 
strickddCommented:
"...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+
0
 
Jesper ChristensenProgrammerAuthor Commented:
Thanks guys
0
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.