看到有的主页登录页面上在登录用户名下有登录保留的选项(下拉),这样如果选择关闭网页后立即失效就可实现下次不自动记住用户名。请问这是如何实现的。是不是和cookies有关系。
谢谢!

解决方案 »

  1.   

    http://www.grrb.com.cn/bbs/login.asp
    想要实现如上图的效果!
      

  2.   

    /// <summary>
    /// 设置cookie保存时间
    /// </summary>
    /// <param name="u">用户对象</param>
    /// <param name="time">多少天</param>
    public static void SetLoginCookie(Bmhd.Components.Components.User u, int days)
    {
    BmhdContext bmhdContext = BmhdContext.Current;
    bmhdContext.Context.Response.Cookies["UserInfo"]["Nickname"] = u.Nickname;
    bmhdContext.Context.Response.Cookies["UserInfo"]["UserID"] = u.ID.ToString();

    if (0 == days)
    {
    System.Web.Security.FormsAuthentication.SetAuthCookie(u.Name, false);
    }
    else
    {
    System.Web.Security.FormsAuthentication.SetAuthCookie(u.Name, true);
    bmhdContext.Context.Response.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddDays(days);
    bmhdContext.Context.Response.Cookies["UserInfo"].Expires = DateTime.Now.AddDays(days);
    }
    }
      

  3.   

    如果关闭浏览器失效,用SESSION,如果需要关闭浏览器后再打开浏览器还可以进行访问用cookies。