Hai guys,
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.
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);
}
Take a look here: How to: Create an ASP.NET Login Page
<asp:Login ID="Login1"
runat="server"
DestinationPageUrl="~/MembersHome.aspx">
</asp:Login>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.