cookie问题...
HttpCookie cookie = new HttpCookie( "mycookie ");
DateTime time = new DateTime();
cookie.Values.Add( "UserName ", Txt_UserName.Value);
cookie.Expires = time.AddMonths(1);
Response.AppendCookie(cookie);
这样写入cookie有问题吗.. 为什么我在读的时候总读不出呢..
读的代码:
HttpCookie readcookie = Request.Cookies[ "mycookie "];
string _user;
_user = readcookie.Values[ "UserName "];
总是报未将对象引用或者设置到对象的实例..应该是没有值原因..
查看cookie文件夹也没有找到对应的cookie..
求解
------解决方案--------------------你这样子试试...
Response.Cookies.Add(myCookie);
另外,时间,你用
cookie.Expires = DateTime.Now.AddMonths(1);