饼干总是在asp.net返回null

问题描述:

网的网页,在第一个,我写了象下面这样:饼干总是在asp.net返回null

protected void lbXML_Click(object sender, EventArgs e) 
{ 
    HttpCookie cookie = new HttpCookie("RequestedXML"); 
    cookie["xmlContent"] = hide_XML.Value; 
    Response.Cookies.Add(cookie); 
    cookie.Expires = DateTime.Now.AddMinutes(20); 
    Response.Write("<script>window.open('XML_Editor.aspx', '_blank', 'toolbar=no, location=no, resizable=yes, width=800px, height=500px', true);</script>"); 
} 

在XML_Editor.aspx,我写了这样的代码:

protected void Page_Load(object sender, EventArgs e) 
{ 
    Page lastPage = (Page)Context.Handler; 
    if (!IsPostBack) 
    { 

     HttpCookie cookie = Request.Cookies["RequestedXML"]; 
     if (cookie != null) 
     { 
      TextBox1.Text = cookie["xmlContent"]; 
     } 

    } 
} 

问题在于,XML_Editor.aspx中的Page_Load Cookie始终将null返回给我,为什么?

+0

你是在本地或远程服务器上的测试呢? –

你的问题可能是你的代码,试试吧:

HttpCookie cookie = new HttpCookie("RequestedXML"); 
      cookie.Value =hide_XML.Value; 

      cookie.Expires = DateTime.Now.AddMinutes(20); 
      Response.Cookies.Add(cookie); 
      Response.Write("<script>window.open('XML_Editor.aspx', '_blank', 'toolbar=no, location=no, resizable=yes, width=800px, height=500px', true);</script>"); 

XML_Editor.aspx

Page lastPage = (Page)Context.Handler; 
      if (!IsPostBack) 
      { 

       var cookie = Request.Cookies["RequestedXML"]; 
       if (cookie != null) 
       { 
        Response.Write(cookie.Value); 
       } 

      } 
+0

不,我的意思是Request.Cookies [“RequestedXML”];总是返回null,我不知道为什么。 – user2575502