首页 > 代码库 > 关于Cookie
关于Cookie
#region 创建cookie
/// <summary>
/// 创建cookie
/// </summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
public static void CreateCookie(string childCookie, string value)
{
if (HttpContext.Current.Request.Cookies["LoanAssess"] != null && HttpContext.Current.Request.Cookies["LoanAssess"].Value != "")
{
HttpCookie cookies = HttpContext.Current.Request.Cookies["LoanAssess"];
cookies.Values[childCookie] = value;
cookies.Expires = DateTime.Now.AddDays(1);
HttpContext.Current.Response.AppendCookie(cookies);
}
else
{
HttpCookie newcookie = new HttpCookie("LoanAssess");
newcookie.Values[childCookie] = value;
newcookie.Expires = DateTime.Now.AddDays(1);
HttpContext.Current.Response.AppendCookie(newcookie);
}
}
#endregion
#region 得到cookie值
/// <summary>
/// 得到cookie值
/// </summary>
/// <param name="childKey">子键cookie</param>
/// <returns></returns>
public static string GetCookieValue(string childKey)
{
string cookieValuehttp://www.mamicode.com/= "";
HttpCookie cookies = HttpContext.Current.Request.Cookies["LoanAssess"];
if (cookies != null && cookies.Values[childKey] != null)
{
cookieValue = http://www.mamicode.com/cookies.Values[childKey];
}
return HttpUtility.UrlDecode(cookieValue);
}
#endregion
关于Cookie