如何使用记住我在logi时检查 [英] how to use remember me check at the time of logi

查看:109
本文介绍了如何使用记住我在logi时检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我在asp.net中启用新功能

Can anybody help me plz im new in asp.net

推荐答案

这取决于你的身份验证库他们希望如何启用一个足够长的cookie来提供记住我的功能。



举个例子,我在一年前创建了一个认证系统,同时学习了系统本身。我用来提供记住我功能的代码只是为了增加cookie过期的时间限制。简单,看看代码,



That depends on your authentication library how they expect to enable a cookie that stays longer enough to provide the functionality of "remember me".

Just for an example, I create an authentication system back a year ago while learning the system itself. The code that I used to provide the "remember me" functionality was just to increase the time limit after which the cookie would expire. Simple, have a look at the code,

if (rememberMe)
{
    // Add 5 days to the stack!
    loginCookie.Expires = DateTime.Now.AddDays(5);
}
else
{
    // Let him in for just 5 hours. 
    loginCookie.Expires = DateTime.Now.AddHours(5);
}





我无法向你提供我写过的文章,因为它有bug,但你可以确定阅读GitHub上该系统的代码: https://github.com/De-Codes/LoginKeys [ ^ ]。


执行以下代码:

Do the following code:
// on Login button click set the cookie with username/email and password
protected void loginBtn_Click(... ...)
{
    if (rememberMeChk.Checked)
    {
        Response.Cookies["Email"].Expires = DateTime.Now.AddDays(30);
        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
    }
    else
    {
        Response.Cookies["Email"].Expires = DateTime.Now.AddDays(-1);
        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
 
    }
    Response.Cookies["Email"].Value = txtUserName.Text.Trim();
    Response.Cookies["Email"].Value = txtPassword.Text.Trim();
}

//Now in Page_Load event we will check if the Cookie exists:
protected void Page_Load(... ...)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["Email"] != null && Request.Cookies["Password"] != null)
        {
            txtUserName.Text = Request.Cookies["Email"].Value;
            txtPassword.Attributes["value"] = Request.Cookies["Password"].Value;
        }
    }
}





-KR



-KR


这篇关于如何使用记住我在logi时检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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