You only need to write these 3 methods in the controller. (Note that it must be written in the controller)
protected string GetCookies(string key)
{
HttpContext.Request.Cookies.TryGetValue(key, out string value);
if (string.IsNullOrEmpty(value))
value = string.Empty;
return value;
}
public void SetCookies(string key, string value, int days = 30)
{
HttpContext.Response.Cookies.Append(key, value, new CookieOptions
{
Expires = DateTime.Now.AddDays(days)
});
}
protected void DeleteCookies(string key)
{
HttpContext.Response.Cookies.Delete(key);
}
I dare not say that this is the best way, but I want to say that it is effective.
Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).
There is 20h05m04s left until you can comment.