Why can't I use HttpContext
or HttpCookie
?
Is there a special using?
My actual usings:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
My namespace:
namespace eCoffee.Main
My class + methods:
public class AppRunCookie
{
public static string CookieName { get; set; }
public static string Key { get; set; }
public AppRunCookie(string key)
{
CookieName = "MyCookie_" + key;
}
public static void SetCookie(string key, int cookieExpireDate = 30)
{
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie["Key"] = key;
myCookie.Expires = DateTime.Now.AddDays(cookieExpireDate);
HttpContext.Current.Response.Cookies.Add(myCookie);
}
public string GetCookie()
{
HttpCookie myCookie = HttpContext.Current.Request.Cookies[CookieName];
if (myCookie != null)
{
string key = Convert.ToString(myCookie.Values["Key"]);
return key;
}
return "";
}
}
What am I do wrong?