Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using newtonsoft. JSON;
Namespace xys. petshop. Web
{
Public class cookie <t>
{
Public static void setcookie (string name, t tvalue, datetime expires)
{
String value = jsonconvert. serializeobject (tvalue );
Httpcookie cookie = new httpcookie (name, value );
Cookie. expires = expires;
Httpcontext. Current. response. Cookies. Add (cookie );
}
Public static t getcookie (string name)
{< br> httpcookie cookie = httpcontext. Current. Request. Cookie [name];
If (cookie! = NULL)
{< br> return jsonconvert. deserializeobject (cookie. value);
}< br> else
return default (t);
}
Public static void removecookie (string name)
{< br> httpcookie cookie = new httpcookie (name);
cookie. expires = datetime. now. adddays (-1);
httpcontext. current. response. cookies. add (cookie);
}< BR >}