2017-01-09 76 views
0

網的網頁,在第一個,我寫了象下面這樣:餅乾總是在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

你是在本地或遠程服務器上的測試呢? –

回答

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