Page1.aspx:
-----------------------------------------
void Page_Load(){
if(!Page.IsPostBack){
if(Request.Cookies["OID"]==null){
HttpCookie htc=new HttpCookie("OID");
htc.Secure=true;
htc.Expires=System.DateTime.Now.AddDays(1);
htc.Value=System.DateTime.Now.ToString();
Response.Cookies.Add(htc);
Response.Write(Request.Cookies["OID"].Name+"|"+Request.Cookies["OID"].Value);
}
else Response.Write(Request.Cookies["OID"].Name+"|"+Request.Cookies["OID"].Value);
}
}
void mGetOID(object sender,EventArgs e){ //Event of Button 
Response.Redirect("Page2.aspx");
}
---------------------------------
Page2.aspx
void Page_Load(){
if(Request.Cookies["OID"]!=null){
Response.Write(Request.Cookies["OID"].Name+"|"+Request.Cookies["OID"].Value+"|"+Request.Cookies["OID"].Expires+"|"+Request.Cookies["OID"].Domain);
}
else Response.Write("Cand find Cookie[OID]!");
}
-----------------------------------
运行Page1后,点击按钮跳转到Page2.结果如下:
----
Cand find Cookie[OID]! 
----也就是说,Cookie没有被写入!或者我读取的方法有误?达人指教,急,谢谢!
浏览器可以接受其它网站的cookie.

解决方案 »

  1.   

    如下代码测试正常
    在a.aspx页面中如下写:
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!this.IsPostBack)
    {
    if(this.Request.Cookies["OID"] == null)
    {
    HttpCookie htc=new HttpCookie("OID");
    htc.Value = "OID";
    this.Response.Cookies.Add(htc);
    }
    else
    {

    } this.Response.Redirect("webform1.aspx");
    }
    }
    在webform1.aspx页面中如下写:
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(this.Request.Cookies["OID"] != null)
    {
    this.Response.Write(this.Request.Cookies["OID"].Value);
    }
    else
    {
    this.Response.Write("无法找到Cookies");
    }
    }
      

  2.   

    好像和计算机有关,有些计算机可以使用。而我的计算机是允许Cookie 的!