【问题标题】:RememberMe option in an asp.net web applicationasp.net Web 应用程序中的 RememberMe 选项
【发布时间】:2011-01-07 05:04:58
【问题描述】:

大家好,

【问题讨论】:

    标签: asp.net web-applications remember-me


    【解决方案1】:

    如果您使用表单身份验证,只需将 true 作为第二个参数传递给 RedirectFromLoginPage

    否则,思路基本相同:你需要创建一个所谓的“persistent cookie”,这意味着你必须指定正确的cookie过期日期。

    【讨论】:

      【解决方案2】:

      看这里:How to: Create an ASP.NET Login Page

      <asp:Login ID="Login1" 
                 runat="server" 
                 DestinationPageUrl="~/MembersHome.aspx">
      </asp:Login>
      

      【讨论】:

        【解决方案3】:
        protected void Page_Load(object sender, EventArgs e)
                {
                    if (!IsPostBack)
                    {
                        if (Request.Cookies["myCookie"] != null)
                        {
                            HttpCookie cookie = Request.Cookies.Get("myCookie");
                            txtUserName.Text = cookie.Values["username"];
                            txtPassword.Attributes.Add("value", cookie.Values["password"]);
        
        
        
                        }
                    }
        
                }
         protected void btnLogin_Click(object sender, EventArgs e)
                {
         bool IsRemember = chkRememberMe.Checked;
                            if (IsRemember)
                            {
                                myCookie.Values.Add("username", txtUserName.Text);
                                myCookie.Values.Add("password", txtPassword.Text);
                                myCookie.Expires = DateTime.Now.AddDays(15);
                            }
                            else
                            {
                                myCookie.Values.Add("username", string.Empty);
                                myCookie.Values.Add("password", string.Empty);
                                myCookie.Expires = DateTime.Now.AddMinutes(5);
                            }
         Response.Cookies.Add(myCookie);
        }
        

        【讨论】:

        • 但是,此解决方案会将用户密码以明文形式保存在他/她的计算机上。
        猜你喜欢
        • 2010-09-21
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-05
        • 1970-01-01
        相关资源
        最近更新 更多