如何为ASP:Login记住我的功能编写代码? [英] how to write code for ASP:Login Remember Me functionality?

查看:68
本文介绍了如何为ASP:Login记住我的功能编写代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的登录页面中,我有一个检查框,即记得我.现在我想用相同的用户名检查下一次登录,它将使用该密码.我该如何编写代码?任何机构都可以为此问题发送代码吗?

Hi,
in my login page i have one check bix is there.i.e., remember me .Now i want to check next time login with same userid it will take that password.How can i write code? Any body can send Code for this Question?

推荐答案

使用 ^ ].它具有下次记住我的功能.
Use ASP.NET Login Control[^]. It has a feature for Remember Me next time.


基本上,您可以使用Cookie来实现此功能.

首次检查:
Basically, you can achieve this functionality using cookies.

For the first time, check:
if (chkRememberPassword.Checked == true)
{
   Response.Cookies["UserName"].Value = txtUserName.Text;
   Response.Cookies["Password"].Value = txtPassword.Text;

   // set cookie expiration in a month
   Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1);
   Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1);
}
else
{
Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1);
Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(-1);
}



然后在您的Page_Load中执行以下操作:



And do the following in your Page_Load:

if (!IsPostBack)
{
   // If cookie exists then set the values from before
   if (Request.Cookies["UserName"] != null)
      txtUserName.Text= Request.Cookies["UserName"].Value;
   if (Request.Cookies["Password"] != null)
      txtPassword.Text.Attributes.Add("value", Request.Cookies["Password"].Value);
   if (Request.Cookies["UserName"] != null && Request.Cookies["UserName"] != null)
      chkRememberPassword.Checked = true;
}



试试吧!



Try!


这篇关于如何为ASP:Login记住我的功能编写代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆