这是Cookie的常用的方法,保存Cookie的值,获取Cookie的值,Function:
public class CookieUtil
{
public static void SaveCookie(HttpRequest request, HttpResponse response, string entry, string name, string value)
{
HttpCookie cookie = request.Cookies[entry];
if (cookie == null)
{
cookie = new HttpCookie(entry);
cookie.Expires = DateTime.Now.AddYears(10);
}
cookie[name] = value;
response.Cookies.Add(cookie);
}
public static string GetCookieValue(HttpRequest request, string entry, string name)
{
if (request.Cookies[entry] != null)
{
if (request.Cookies[entry][name] != null)
{
return request.Cookies[entry][name];
}
}
return null;
}
}