CSDN博客

img maseccc

在login控件中加入"remember me on next login"

发表于2008/9/28 13:35:00  1215人阅读

I will show you how easy it is to add a "remember me on next login" feature so people is automatically logged in when visiting your site in the future.

First just add a checkbox (I havn't renamed it in this sample, just calling it CheckBox1) in your login form:

Then in your code handler for the button click:

 
 
private void btnLogin_Click(object sender, System.EventArgs e)  
{  
    if ( FormsAuthentication.Authenticate(txtID.Text, txtPwd.Text) )  
    { //It went well         
        FormsAuthentication.RedirectFromLoginPage(txtID.Text,CheckBox1.Checked);  
    }  
    else  
    {  
    LabelError.Text = "Error logging in";  
    }  

So the last parameter to RedirectFromLoginPage is CheckBox1.Checked which will then handle everything from us.

Under the hood it is of course solved by setting a cookie, but that's nothing we have to worry about. Sometimes you just gotta love ASP.NET !

 

0 0

相关博文

我的热门文章

img
取 消
img