日期:2014-05-18  浏览次数:20457 次

Cookies的问题,急!!!!!
代码是这样的
FormsAuthenticationTicket   ticket   =   new   FormsAuthenticationTicket(1,   tbName.Text,   DateTime.Now,   DateTime.Now.AddMinutes(20),   cbIsPersistent.Checked,   userID.ToString(),   FormsAuthentication.FormsCookiePath);  
//加密  
string   encTicket   =   FormsAuthentication.Encrypt(ticket);  
//添加到Cookies  
HttpCookie   myCookie   =   new   HttpCookie(FormsAuthentication.FormsCookieName,   encTicket);  
if   (cbIsPersistent.Checked)  
{  
myCookie.Expires   =   DateTime.Now.AddDays(14);  
}  
Response.Cookies.Add(myCookie);  
//转到请求页面  
Response.Redirect(FormsAuthentication.GetRedirectUrl(tbName.Text,   cbIsPersistent.Checked));  
这样如果cbIsPersistent.Checked是true是不是就把Cookie保存到了客户端Cookie文件中了?  
那下次打开网站的时候怎么取Cookie中的FormsAuthenticationTicket?  
在那里取?  
现在下次打开网站还是得登录!!!!!!!急

------解决方案--------------------
try ->

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, tbName.Text, DateTime.Now, DateTime.Now.AddMinutes(20), cbIsPersistent.Checked, userID.ToString(), FormsAuthentication.FormsCookiePath);

> > >

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, tbName.Text, DateTime.Now,
DateTime.Now.AddDays(14), // here
cbIsPersistent.Checked, userID.ToString(), FormsAuthentication.FormsCookiePath);