tkt = new FormsAuthenticationTicket(1,userid,DateTime.Now,DateTime.Now.AddMinutes(30),true,"usertkt"); //这里的时间改成你要的 cookiestr=FormsAuthentication.Encrypt(tkt); ck = new HttpCookie(FormsAuthentication.FormsCookieName,cookiestr); ck.Path=FormsAuthentication.FormsCookiePath;//cookie存放路径 Response.Cookies.Add(ck);
tkt = new FormsAuthenticationTicket(1,userid,DateTime.Now,DateTime.Now.AddMinutes(30),true,"usertkt"); //这里的时间改成你要的
cookiestr=FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName,cookiestr);
ck.Path=FormsAuthentication.FormsCookiePath;//cookie存放路径
Response.Cookies.Add(ck);
myCookie.Value = "输入的用户名或密码值";
//TimeSpen(14,0,0,0))为天,小时,分,秒。
myCookie.Expires = TimeDate.Now.Add(new TimeSpan(14,0,0,0));
Response.Cookies.Add(myCookie);
//另一个页面输出Cookie
HttpCookie myCookie = Request.Cookies["user"]
if(myCookie == null)
{
Response.Redirect(“login.aspx”);
}
else
{
//进入页面
}
我觉得也是用cookies,cookies的时间设成比如1000年什么的,就可以算是永久登录了,哈哈.
请问你的方法会不会有什么局限呢?