Recovery
Recovery

Reputation: 45

How can I use HttpContext in public class

How can I use HttpContext in public class. I have all method about Cookies in one class without this:

        public HttpCookie SetAndGetHttpCookies()
    {
        HttpCookie cookie = HttpContext.Request.Cookies.Get("MyCookieGitApplication");
        CookieHelper cookieHelper = new CookieHelper();

        if (cookie == null)
        {
            cookie = cookieHelper.SetCookie();
        }

        return cookie;
    }

Any idea how can I use HttpContext.Request in public class? Maybe someone have different way to get cookies?

Upvotes: 1

Views: 80

Answers (1)

Gilthans
Gilthans

Reputation: 1726

Have you tried HttpContext.Current? If you're using ASP.NET this should be a way to access the current context from anywhere in your code. If you're not, the solution is trickier.

I.E.

    HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("MyCookieGitApplication");

Upvotes: 2

Related Questions