How to store multiple username and passwords in cookies in c#? I tried But it stores only one username and password.
protected void Login_Click(object sender, EventArgs e)
{
if (chkRememberMe.Checked)
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
}
else
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
}
Response.Cookies["UserName"].Value = txtUserName.Text.Trim();
Response.Cookies["Password"].Value = txtPassword.Text.Trim();
}
Cookies are stored per-user, so your code should work as-is.
I would strongly recommend that you do not store usernames and passwords in user cookies though due to the security issues associated with this. Use the built-in authentication, which stores a session identifier instead.
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.