就是可以选保存时间,以后不用每次都登陆。是用cookie来记录吗?怎样读取?

解决方案 »

  1.   

    FormsAuthentication.SetAuthCookie(UserName.Text,true);即可
      

  2.   

    FormsAuthenticationTicket tkt;

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

  3.   

    HttpCookie myCookie = new HttpCookie("user");
    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
    {
    //进入页面
    }
      

  4.   

    FormsAuthentication.SetAuthCookie(UserName.Text,true);即可孟子这个好像是forms验证的时候的吧,如果是windows验证,就不是这个了吧.
    我觉得也是用cookies,cookies的时间设成比如1000年什么的,就可以算是永久登录了,哈哈.
      

  5.   

    ll_e_mail() 的方法简单易懂,但我看到似乎FormsAuthentication类用于保存密码的很多。
    请问你的方法会不会有什么局限呢?