• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 389
  • Last Modified:

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")
0
Jesper Christensen
Asked:
Jesper Christensen
  • 3
  • 2
1 Solution
 
käµfm³d 👽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
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
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 ChristensenAuthor Commented:
Thanks guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now