关键的是Server.UrlEncode()、Server.UrlEncode() 这2个方法
public void SetCookie(string CookieName, string CookieValue, int CookieDays)
{
HttpCookie ctrCookie;
if (Request.Cookies[CookieName] == null)
{
ctrCookie = new HttpCookie(CookieName);
}
else
{
ctrCookie = Request.Cookies[CookieName];
}
ctrCookie.Value = Server.UrlEncode(CookieValue);
ctrCookie.Expires = DateTime.Now.AddDays(CookieDays);
Response.Cookies.Add(ctrCookie);
}
public string GetCookie(string CookieName)
{
if (Request.Cookies[CookieName] != null)
return Server.UrlDecode(Request.Cookies[CookieName].Value);
else return "";
}
时间: 2024-10-26 19:46:46