asp.net is it possible to read the value of a cookie from a static class?

asp.net, cookies

Solution

using System.Web;
...
return HttpContext.Current.Request.Cookies["MyField"];

Problem

I have a CurrentUser class with a static property whose value was stored in a cookie last time the user visited the website. I would like to be able to read the value of the cookie from this class. Is it possible? It looks like Request.Cookies is only available in web pages. A simplified version of what I'm trying to do is: ``` class CurrentUser { public static string MyField { get { return Request.Cookies["MyField"]; } } } ``` This doesn't work. I get this error message: "the name 'Request' does not exist in the current context'.

Original source