在A页面中,设置Cookies值:
HttpCookie httpCookie;
if (HttpContext.Current.Request.Cookies[name] != null)
    HttpContext.Current.Request.Cookies.Remove(name);
httpCookie = new HttpCookie("cookieTest","Hello,world!");
httpCookie.Expires = DateTime.Now.AddHours(10);
HttpContext.Current.Response.AppendCookie(httpCookie);用IE打开B页面,在B页面中,读Cookies:
HttpCookie httpCookie;
string value = null;httpCookie = HttpContext.Current.Request.Cookies[name];
if (httpCookie != null)
    value = httpCookie.Value;

问题现象:
httpCookie 为 null另外:
如果不用IE打开B页面,而从A页面打开B页面,却可以读到 Cookies。
A、B两个页面在同一工程。

解决方案 »

  1.   

    补充:
    // httpCookie.Expires = DateTime.Now.AddHours(10);
    这句代码是注释掉了。
      

  2.   

    将httpCookie.Path改成“/”或者其他A、B的公共父目录
      

  3.   

    未对应起来写cookie HttpCookie httpCookie;
    if (HttpContext.Current.Request.Cookies["name"] != null)
    HttpContext.Current.Request.Cookies.Remove("name");
    httpCookie = new HttpCookie("name","Hello,world!");
    httpCookie.Expires = DateTime.Now.AddHours(10);
    HttpContext.Current.Response.AppendCookie(httpCookie);
    读cookieHttpCookie httpCookie;
    string tt=null;httpCookie = HttpContext.Current.Request.Cookies["name"];
    if (httpCookie != null)
        tt = httpCookie.Value;
    Response.Write(tt);
      

  4.   

    另外,楼主使用的value是系统的保留字使用数组时,应有""
      

  5.   

    路径的方法我试了一下,还是不行哈.注意:
    需要达到的是不要设置 Cookies 的过期期限。
    就是说问题描述中的 
    httpCookie.Expires = DateTime.Now.AddHours(10);
    这句代码被注释掉******
      

  6.   

    如果加上
    httpCookie.Expires = DateTime.Now.AddHours(10);
    整个功能是问题的
    现在讨论的是不要那句代码
      

  7.   

    如果加上
    httpCookie.Expires = DateTime.Now.AddHours(10);
    整个功能是没有问题的
    现在讨论的是不要那句代码