QueUe
QueUe

Reputation: 101

Read cookies inside a static method

I have problem with reading cookies inside a static method. I tried:

static void Method()
{
    Page page = HttpContext.Current.Handler as Page;
         HttpCookie reader= page.Request.Cookies["myCookie"];
}

but I think it doesn't work.

Do you have any ideas how can I do this?

Upvotes: 3

Views: 4141

Answers (1)

theSKa
theSKa

Reputation: 51

Please read the documentation on msdn regarding cookies in asp.net here. My guess is that you don't need the Handler in order to read the cookies. See what HttpContext.Handler is.

I recommend you to try out:

static void Method()
{
    HttpCookie reader = HttpContext.Current.Request.Cookies["myCookie"];
}

Upvotes: 5

Related Questions