c#(.net)的cookie操作错误?
这段程序运行出错,我的环境:winXP+iis+framework2.0<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
HttpCookie cookie = new HttpCookie("aspcn");
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,6,0);
cookie.Expires = dt.Add(ts);
cookie.Values.Add("a","feidao");
cookie.Values.Add("programer1","sunwen");
cookie.Values.Add("programer2","xuankong");
cookie.Values.Add("programer3","buding");
Response.AppendCookie(cookie);
HttpCookie readcookie = Request.Cookies["aspcn"];
//Cookie1.Text = readcookie.Values["a"].ToString();
Cookie2.Text = readcookie.Values["programer1"].ToString();
Cookie3.Text = readcookie.Values["programer2"].ToString();
Cookie4.Text = readcookie.Values["programer3"].ToString();
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<b>演示设置多个Cookie的值</b><br>
<form runat="server">
Cookie1的值是:<asp:Label id="Cookie1" ForeColor="red" runat="server" /><br>
Cookie2的值是:<asp:Label id="Cookie2" ForeColor="red" runat="server" /><br>
Cookie3的值是:<asp:Label id="Cookie3" ForeColor="red" runat="server" /><br>
Cookie4的值是:<asp:Label id="Cookie4" ForeColor="red" runat="server" /><br>
</form>
</body>
</html>
--------------------编程问答-------------------- f --------------------编程问答-------------------- 当然出错拉写是写到Response里面去的, 而你是从Request里面读
Response.Cookies != Request.Cookies
下一个请求你才能从request中读出上个请求response的cookie
补充:.NET技术 , C#