110,545
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
setCookie("namex", "mxh", 30);
Response.Write("-----------------------" + Request.Cookies["namex"].Value);
}
public static void setCookie(string key, string value, int timeout)
{
try
{
HttpCookie cookie = new HttpCookie(key);
value = HttpUtility.UrlEncode(value);
cookie.Value = value;
cookie.Domain = ".test.com";
cookie.Path = "/";
cookie.Secure = false;
if (timeout != 0)
cookie.Expires = DateTime.Now.AddMinutes(Convert.ToInt32(timeout));
HttpContext.Current.Response.Cookies.Add(cookie);
}
catch
{
}
}
Response.Write("---------------"+Request.Cookies["namex"].Value);