日期:2014-05-19  浏览次数:20416 次

我急啊!555555555555
我的COOKIES保存起了,但是调用的时候就把cookies文件从系统中删除了。我是亲眼看   到的。
      我是这样写的:
<asp:Button   ID= "ds "   runat= "server "   Text= "查看cookies "   OnClick= "ds_Click "   />
<asp:Button   ID= "Button1 "   runat= "server "   OnClick= "Button1_Click "   Text= "保存cookies "   />
后台代码:
        protected   void   ds_Click(object   sender,   EventArgs   e)
        {
                Response.Write(Response.Cookies[ "myuser "].Value);
                Response.Write(Response.Cookies[ "myuser "].Expires.ToString());
        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                Response.Cookies[ "myuser "].Value   =   "ffdsalkfjdsal ";
                Response.Cookies[ "myuser "].Expires   =   DateTime.Now.AddHours(60);
               
        }



------解决方案--------------------
sf
------解决方案--------------------
关注
------解决方案--------------------
HttpCookie objHttpCookie = new HttpCookie(“UserName”,“张三 "); //设置Cookie内容
objHttpCookie.Expires = DateTime.Now.AddMinutes(2);//设置时间
Response.Cookies.Add(objHttpCookie); //添加到客户端

------解决方案--------------------
查看的时候要用request Response.Write(Request.Cookies[ "myuser "].Value); Response.Write(Request.Cookies[ "myuser "].Expires.ToShortDateString());
------解决方案--------------------
到底什么问题嘛?
给出出错的代码,
建议你单步调试,不一定是保存的时候删除,可能是其他地方的代码对这个影响了?
------解决方案--------------------
显示你用request.cookies

------解决方案--------------------
Response.Write(Response.Cookies[ "myuser "].Value);
Response.Write(Response.Cookies[ "myuser "].Expires.ToString());

这句怎么看的这么别扭,response本来就是响应,怎么还这样嵌套 啊?
Response.Write(Request.Cookies[ "myuser "].Value);
Response.Write(Request.Cookies[ "myuser "].Expires.ToShortDateString());
应该这样吧?
------解决方案--------------------
Response.Cookies[ "myuser "].Value

换成cookies.values[ "myuser "];