菜鸟cookie大问题,在线等,救命呀
上一页:
HttpCookie cookie = new HttpCookie("aspcn");
DateTime dt = DateTime.Now;
TimeSpan ts = new TimeSpan(0,0,6,0);
cookie.Expires = dt.Add(ts);
while(dr.Read())
{
cookie.Values.Add("webmaster","admin");
cookie.Values.Add("programer1","pwd");
cookie.Values.Add("programer2","grade");
cookie.Values.Add("programer3","username");
cookie.Values.Add("programer2","ipaddresslast");
cookie.Values.Add("programer3","department");
}
Response.AppendCookie(cookie);
Response.Redirect ("dep_admin_lk.aspx");
下一页:
HttpCookie readcookie = Request.Cookies["aspcn"];
Cookie1.Text = readcookie.Values["admin"].ToString();
出现出错信息:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 7: HttpCookie readcookie = Request.Cookies["aspcn"];
Line 8:
Line 9: Cookie1.Text = readcookie.Values["admin"].ToString();