问题
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