RememberMe option in an asp.net web application

陌路散爱 提交于 2019-12-11 09:20:48

问题


Hai guys,

  • what are the possible ways of implementing remember me option in an asp.net web application? alt text http://www.freeimagehosting.net/uploads/0f9ebba1bb.jpg

回答1:


If you're using Forms Authentication, just pass true as a second argument to RedirectFromLoginPage.

Otherwise, idea is essentially the same: you need to create a so-called "persistent cookie", which means that you have to specify correct cookie expiration date.




回答2:


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



回答3:


Take a look here: How to: Create an ASP.NET Login Page

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


来源:https://stackoverflow.com/questions/2100449/rememberme-option-in-an-asp-net-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!