首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Cookies的有关问题,

2012-01-06 
Cookies的问题,急!!!!!代码是这样的FormsAuthenticationTicketticketnewFormsAuthenticationTicket(1,tbN

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);

热点排行